Jump to content

Recommended Posts

Hi,

 

I am new to php and try to compare two dates.

 

From what I have read this is very easy, yet I am struggling to get it to work.

I would like to compare a predefined month to a date field called id_date(YYYY-MM-DD) in my database and output a result according to the date.

 

Here is what I came up with:

 

$dmonth=date('Y-m', strtotime('last month'))

 

This should return 2009-01

 

In the next step

 

SELECT id FROM mytable WHERE date(id_date)='$dmonth'

 

The result is zero although there should be results. I also tried just id_date=.. with the same result and strtotime(id_date) which produced an sql error

 

Probably the id_date is not converted properly but I have no ideas how to achieve that. Any hints or tipps are greatly apreciated. Thanks alot!

 

Link to comment
https://forums.phpfreaks.com/topic/144654-simple-date-comparison-strtotime/
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.