faqts : Computers : Programming : Languages : PHP : Function Libraries : Date and Time

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

52 of 198 people (26%) answered Yes
Recently 2 of 10 people (20%) answered Yes

Entry

How do I compare dates? If I want to display only information entered in one given month(october) and nothing before and nothing after this month.

Nov 10th, 2000 04:59
Henrik Hansen, agnes rynkiewicz, Onno Benschop,


If you have two dates ($date1 and $date2) in the form Y-m-d, you can 
for example use the following:
if($date1 == $date2)
   echo "the dates are identical";
else
   echo "the dates are not the same";
If you only want to display something after a certain month try 
something like this:
//get the month name from our date
$month = substr($date, 5, 2);
//see if the month is equal to this months date
if($month == date("m", time()))
   echo "show the info";