[英]How to find rows from less than 6 months ago in PHP and MySQL, Month By Month
[英]How to show month ago in PHP
$ logintime value 1年完成意味着它將在1年前顯示,但是假設2個月僅完成意味着我想在2個月之前顯示,但是我的代碼顯示像60天之前,我不知道我在哪里犯了錯誤,剩下小時,分鍾,這工作正常,只有月份問題, $logintime = 2016-02-27 03:00:00
function timeAgo($logintime) {
date_default_timezone_set('UTC');
date_default_timezone_set('Asia/Kolkata');
$start_date = new DateTime($logintime);
$since_start = $start_date->diff(new DateTime(date("Y-m-d h:i:s")));
if (intval($since_start->format('%Y') ) >= 1) {
echo $year = $since_start->format('%Y years ago');
} else if (intval($since_start->format('%m')) >= 12) {
echo $months = $since_start->format('%m month ago');
} else if (intval($since_start->format('%a')) >= 1) {
echo $days = $since_start->format('%a days ago');
} else if (intval($since_start->format('%h')) >= 1) {
echo $hourss = $since_start->format('%h hours ago');
} else if (intval($since_start->format('%i')) >= 1) {
echo $min = $since_start->format('%i minuts ago');
} else if (intval($since_start->format('%s')) >= 1) {
echo $min = $since_start->format('%s seconds ago');
}
}
您這行代碼:
else if(intval($since_start->format('%m')) >= 12){
它說如果月份> = 12,則顯示幾個月前,但您只有2個月。
因此,您應該考慮將其更改為:
else if(intval($since_start->format('%m')) >= 1){
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.