alin19 Posted March 20, 2008 Share Posted March 20, 2008 let's say that i have something like this: <?php $x=date ("Y-m-d"); $y=date ("2008-03-24"); if ($x<$y) echo "$y is in the future"; ?> how can i do something like this? Link to comment https://forums.phpfreaks.com/topic/97117-comparing-two-dates/ Share on other sites More sharing options...
BlueSkyIS Posted March 20, 2008 Share Posted March 20, 2008 $y=date ("2008-03-24"); is invalid syntax. if you want to subtract the given y from x, i'd: $x = time(); $start_y = "2008-03-24"; $y = strtotime($start_y); if ($x < $y) { echo "$start_y is in the future"; } Link to comment https://forums.phpfreaks.com/topic/97117-comparing-two-dates/#findComment-496921 Share on other sites More sharing options...
PFMaBiSmAd Posted March 20, 2008 Share Posted March 20, 2008 Because the time() function includes the current HH:MM:SS on the server and the strtotime() of a just a date will use 00:00:00, other types of comparisons between the two values won't always give correct results nor would any math. If you want all comparisons (<, >, ==, <=, >=, !=) and any math between two dates to work, the time portion must be equivalent. Link to comment https://forums.phpfreaks.com/topic/97117-comparing-two-dates/#findComment-497138 Share on other sites More sharing options...
Barand Posted March 21, 2008 Share Posted March 21, 2008 You can compare the date strings without the time conversions <?php $x=date ("Y-m-d"); $y='2008-03-24'; if ($x<$y) echo "$y is in the future"; ?> Link to comment https://forums.phpfreaks.com/topic/97117-comparing-two-dates/#findComment-497246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.