Jump to content

[SOLVED] Comparing dates


soycharliente

Recommended Posts

In my db table, my date field uses YYYY-MM-DD, but if you compared 2007-6-1 to 2007-06-01 you would get FALSE. What can I do about this? I'm passing days using the GET method and then populating an events div with events from a db table that match the D M and Y.

 

I would like it to work for both numbers with and without leading zeros.

 

Link to comment
Share on other sites

Whether they're passed with GET or POST makes no difference. You'll need to process them in some way to get a yyyy-mm-dd string for comparison purposes unless you use a user input method that only allows correctly formed dates, i.e. a dropdown. Meantime, the below should suffice to convert inputs retrieved from a passed array.

 

$iso_date = date("Y-m-d", strtotime(0,0,0,$m,$d,$y));

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.