Jump to content

Compare Dates


searls03

Recommended Posts

I am forming the dates using jquery's datepicker. it shows up as that format and then stores it in a database. I then have a calendar that pulls the date from the database and places it in the calendar. I can't use another format for this, as it is how the calendar is designed to work....believe me, I have tried other formats. I will take a look at the link you provided. I guess maybe I could insert the date into two columns or something and do it that way maybe.

Link to comment
https://forums.phpfreaks.com/topic/272579-compare-dates/#findComment-1402586
Share on other sites

That's not the right way to store dates in a database. In fact it's a pretty bad way to do it since you lose the ability to run comparisons on them, as you've undoubtedly noticed. Dates should be stored in YYYY-MM-DD format.

Link to comment
https://forums.phpfreaks.com/topic/272579-compare-dates/#findComment-1402589
Share on other sites

Some formats work better than others

 

<?php
echo '<b>UK</b><br />';
echo '25/12/2012 --> ' . date('Y-m-d', strtotime('25/12/2012')) . '<br />';
echo '25-12-2012 --> ' . date('Y-m-d', strtotime('25-12-2012')) . '<br />';
echo '25.12.2012 --> ' . date('Y-m-d', strtotime('25.12.2012')) . '<br />';
echo '<b>US</b><br />';
echo '12/25/2012 --> ' . date('Y-m-d', strtotime('12/25/2012')) . '<br />';
echo '12-25-2012 --> ' . date('Y-m-d', strtotime('12-25-2012')) . '<br />';
echo '12.25.2012 --> ' . date('Y-m-d', strtotime('12.25.2012')) . '<br />';
?>

RESULTS:

UK
25/12/2012 --> 1970-01-01
25-12-2012 --> 2012-12-25 ok
25.12.2012 --> 2012-12-25 ok
US
12/25/2012 --> 2012-12-25 ok
12-25-2012 --> 1970-01-01
12.25.2012 --> 1970-01-01

Link to comment
https://forums.phpfreaks.com/topic/272579-compare-dates/#findComment-1402674
Share on other sites

I don't know which datepicker the OP is using, but any worth their salt would have a customisable output-date format.  I'm with Jessica, in suggesting looking in that direction.  Then you can compare the dates either using PHP's DateTime objects or with plain-old-string-comparison.

Link to comment
https://forums.phpfreaks.com/topic/272579-compare-dates/#findComment-1402757
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.