0

i need code to compare date in php

  1. Input date should be a valid date
  2. input date should not be less than the current date.
  3. i need to give time zones EST,PST,etc..
  4. We need to make the time to GMT and compare with Current Time.

can anyone help on this. Thanks Ramakrishnan.p

Galen
  • 29,976
  • 9
  • 71
  • 89
Ramakrishnan
  • 5,254
  • 9
  • 34
  • 41
  • Have you had a look through the time functions (http://php.net/manual/en/ref.datetime.php), what have you done with them, is there any particular problem you're having? – deceze May 25 '10 at 06:06
  • This has been much discussed already: **[how to compare the two date](http://stackoverflow.com/questions/1496483/how-to-compare-the-two-date)** **[Compare date in php](http://stackoverflow.com/questions/2347082/compare-date-in-php)** **[PHP - Compare Date](http://stackoverflow.com/questions/2113940/php-compare-date)** **[PHP How to compare date and date?](http://stackoverflow.com/questions/2355075/php-how-to-compare-date-and-date)** **[Shortest way to compare 2 dates in dd/mm/yyyy format](http://stackoverflow.com/questions/2729680/shortest-way-to-compare-2-dates-in-dd-mm-yyyy-format)** **[And – Sarfraz May 25 '10 at 06:05

3 Answers3

4

This is a late answer. since there is no exact answer to the question here, I'm providing this solution here.

You can do it in this way

$date1 = strtotime("2007-02-20"); // your input
$date2 = strtotime("today"); //today
if($date1 < $date2) {
    echo " input date is in the past";
}

strtotime converts the string in to the unix timestamp integer.

Martin
  • 22,212
  • 11
  • 70
  • 132
Strikers
  • 4,698
  • 2
  • 28
  • 58
0

Take a look at the maketime() function. Then compare the resulting UNIX timestamps.

Jan K.
  • 1,607
  • 2
  • 13
  • 22
0

Check out Zend Framework's Date: http://framework.zend.com/manual/en/zend.date.overview.html You just need the Date.php file and the Date/Locale folders from the framework to use it.

typeoneerror
  • 55,990
  • 32
  • 132
  • 223