Jump to content

Simple date comparison - strtotime


Anfaenger

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

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.