-3

I have a date format of DD/MM/YYYY and I want to check in a form submission whether the submitted date is present in the calendar or not.

Code:

$last_date = $_POST['last_date'];

$date = str_replace("/", "-", $last_date);
$d = explode("-"  , $date);

if( !checkdate($d[1], $d[0], $d[2]) )
    error[] = 'Warning! This date does not have any existence.';
halfer
  • 19,824
  • 17
  • 99
  • 186
Arijit Aich
  • 161
  • 1
  • 2
  • 12
  • What calendar are you talking about? There's nothing here that represents a calendar. – John Conde Mar 23 '15 at 20:21
  • @JohnConde You are not getting it correct. I am talking about whether the date exists in the Real Life Calendar. The calendar which we follow. The Gregorian Calendar. – Arijit Aich Mar 23 '15 at 20:24
  • The Chinese don't follow that calendar, and they're about a 5th of the world's population. – James Spence Mar 23 '15 at 20:25
  • http://stackoverflow.com/questions/19271381/correctly-determine-if-date-string-is-a-valid-date-in-that-format/19271434#19271434 –  Mar 23 '15 at 20:25

1 Answers1

1

To validate a Gregorian date you should use PHP's checkdate() function

$date_to_check = checkdate('2', '29', 1969) ? 'good' : 'bad';
echo $date_to_check; // 'bad'
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • 1
    Thanks alot @JayBlanchard. Its always good to see that there are people interested in helping rather than criticizing. Your code worked. – Arijit Aich Mar 23 '15 at 20:50