Php compares two dates. Comparing two dates, YMD has been divided into numbers in the database. for example, Y2020M1D1 is displayed as daydiffdate ($ nowyr. $ nowmon. $ nowdt)-date (Ymd); compare two dates
YMD has been divided into numbers in the database. for example, Y = 2020 M = 1 D = 1
After I extract it, it is displayed as daydiff = date ("$ nowyr". "$ nowmon". "$ nowdt")-date ("Ymd ");
After this subtraction, the number is calculated as negative, 202011-20090305.
How can I convert to 20200101-20090305?
That is, compare the retrieved time in the database with the current time, and subtract the date. if it is the date after the current time, it is positive, otherwise it is negative.
Please help.
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 = "00:00:00 ";
If (strtotime ($ onetime)-time () <0)
{
//
}
Elseif (strtotime ($ onetime)-time ()> 0)
{
//
}
Else
{
//
}
D8888D reply content -------------------------------------------------------
$ Onetime = "00:00:00 ";
If (strtotime ($ onetime)-time () <0)
{
//
}
Elseif (strtotime ($ onetime)-time ()> 0)
{
//
}
Else
{
//
}
D8888D reply content -------------------------------------------------------
If this is not the case, you can convert it into a timestamp [img] http://www.111cn.cn/bbs/images/smilies/default/policy.gif#/img]
D8888D reply content -------------------------------------------------------
I tried, but an error occurred,
Echo date ("M-d-Y", mktime (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 ");
D8888D reply content -------------------------------------------------------
Timestamp
D8888D reply content -------------------------------------------------------
Mktime (0, 0, 0, $ nowdt, $ nowmon, $ nowyr)-time ()
D8888D reply content -------------------------------------------------------
Timestamp
D8888D reply content -------------------------------------------------------
Save a timestamp when saving the date. it doesn't make sense to subtract the date. the year, month, and day carry numbers are inconsistent, and the value is meaningless.
D8888D reply content -------------------------------------------------------
$ Daydiff = (strtotime (date ("$ nowyr ". "-". "$ nowmon ". "-". "$ nowdt")-strtotime (date ("Y-m-d")/86400;
I wrote it like this. it seems that there is no problem to test fixed numbers, but sometimes the number digits are different in the year, month, and day. I don't know if it is true or not. Ah! Not sure ........
Shards have split YMD into numbers in the database. for example, if Y = 2020 M = 1 D = 1, after obtaining it, it is displayed as daydiff = date ("$ nowyr ". "$ nowmon ". "$ nowdt")-date ("Ymd ");...