Jump to content

comparing dates


AdRock

Recommended Posts

I have a form where i have 4 fields

 

1 for the start month and 1 for the start year

1 for the end month and 1 for the end year

 

I am trying to validate it so the the end month/year can't be before the start month/year

 

I have all the other form validation working but need some advice how i can do this last bit

 

Do I have to convert these form values into a date format for comparison and if so, how?

Link to comment
https://forums.phpfreaks.com/topic/103075-comparing-dates/
Share on other sites

An identical approach, but using strtotime():

 

<?php
$startTime = strtotime($_POST['startyear'] . - . $_POST['startmonth']);
$endTime = strtotime($_POST['endyear'] . - . $_POST['endmonth']);
if($endTime < $startTime){
     echo 'End time should be less then start time.';
} else{
     //other code
}
?>

Link to comment
https://forums.phpfreaks.com/topic/103075-comparing-dates/#findComment-528060
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.