1

I am newbe to php. I have small problem to compare dates in php.

I have 4 dates named date1, date2, start_date and end_date in the format yyyy-mm-dd.

i need the functionality like this:

if((date1>=start_date) && (date2<=end_date)){

} 

please help me to solve this.

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
sandeep
  • 2,862
  • 9
  • 44
  • 54

2 Answers2

8

use strtotime to get the timestamps of your dates - this can be easily compared to each other like you already trying it.

oezi
  • 51,017
  • 10
  • 98
  • 115
1

If you have PHP 5.3, this is easily handled by the DateTime and DateDiff classes. If you have not, it is much harder, but look at the 'user contributed' section on DateDiff in the online PHP manual.

Colin Fine
  • 3,334
  • 1
  • 20
  • 32
  • this isn't what sandeep is asking for, he just wan't to compare, not to get the difference - in that case, strtotime is much faster and very easy to use. – oezi Nov 10 '10 at 11:06