开发者

Compare date in php

Task:

I need to check the current time with a respective time fixed by the admin, if the current time crosses the respective time, will update status

1) How can i convert the respective date to unix timestamp ?

TIME STAMP: 1267285500 for DATE: 2 / 27 / 2010 @ 9:45:开发者_运维技巧0

so that i can compare the unix timestamps of the current time and respective time and update the status

2) Is there any easy way that i can acheive this task ?

Thank You,


You may use strtotime and strftime (to get a valid input for strtotime) then get a unix timestamp, and compare them.

Also, you can use date to get back from a unix timestamp to a formated date.


strptime('2 / 27 / 2010 @ 9:45:0', '%m / %e / %Y @ %T'); // This might not work.

Whoever decided that they where not going to use leading zeros kinda screwed you on this one. You might have to parse the date some more to get a full result like this:

list($date, $time) = explode(' @ ', '2 / 27 / 2010 @ 9:45:0');
list($month, $day, $year) = explode(' / ', $date);
list($hour, $minute, $second) = explode(':', $time);

$unixtime = mktime($hour, $minute, $second, $month, $day, $year);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜