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
https://forums.phpfreaks.com/topic/55028-solved-comparing-dates/
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));

I have a calendar with each day being a link that just passes what D M Y it corresponds to into the URL.

 

SO when I process the page, I should take the D M Y from the GET array and use the date() function and mktime() to get the format that I need?

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.