Compare two dates
The YMD has been divided into numbers in the database. For example, Y=2020 M=1 D=1
After I take it out now, it displays as daydiff=date( "$nowyr"."$nowmon"."$nowdt") - date("Ymd");
But after this subtraction, the digital operation is negative, 202011-20090305
How can I convert it to 20200101-20090305
That is, the time retrieved from the database is compared with the current time, and the date is subtracted. If the date is after the current time, it is positive, otherwise it is negative.
Please help me heroes.
Best answer[url=http://www.111cn.cn/bbs/space.php?username=doing]Link tag doing[/url]
[url=http://www.111cn.cn/bbs/space.php?uid=97304]Link tag[img]http://www.111cn.cn/server/avatar.php?uid=97304&size=small[ /img][/url]$onetime = "2010-01-01 00:00:00";
if((strtotime($onetime)-time())
{
//
}
elseif((strtotime($onetime)-time())>0)
{
//
}
else
{
//
}
D8888D reply content------------------------------------------------- ----------
$onetime = "2010-01-01 00:00:00";
if((strtotime($onetime)-time())
{
//
}
elseif((strtotime($onetime)-time())>0)
{
//
}
else
{
//
}
D8888D reply content------------------------------------------------- ----------
If I don't do that, I can consider converting it to a timestamp [img]http://www.111cn.cn/bbs/images/smilies/default/victory.gif[/img]
D8888D reply content------------------------------------------------- ----------
I tried, but got an error,
echo date ("M-d-Y", mktime (0,0,0,$nowdt,$nowmon,$nowyr))-date("Ymd");
D8888D reply content------------------------------------------------- ----------
$nowyr = 2020;
$nowmon = 1;
$nowdt = 1;
echo date( sprintf("%04d%02d%02d", $nowyr, $nowmon, $nowdt)) - date("Ymd");
Copy code
D8888D reply content------------------------------------------------- ----------
Timestamp Ah
D8888D reply content------------------------------------------------- ----------
mktime (0,0,0,$nowdt,$nowmon,$nowyr) - time()
D8888D reply content------------------------------------------------- ----------
Timestamp
D8888D reply content------------------------------------------------- ----------
When saving the date, save a timestamp by the way. Subtracting the date from the date is meaningless. The rounding up of the year, month, and day is inconsistent, and the subtracted value is meaningless
D8888D reply content------------------------------------------------- ----------
$daydiff=(strtotime(date("$nowyr"."-"."$nowmon"."-"."$nowdt")) - strtotime(date("Y-m-d")))/86400;
I wrote it like this. There seems to be no problem with testing fixed numbers, but the year, month, day, and number of digits are sometimes different. I don’t know if there are times when it doesn’t hold true. Why! Not sure yet. . . . . . . .