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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.