Checking a date range : strtotime « String « PHP






Checking a date range

 
<?
// Get the epoch timestamp for 6 months ago
$range_start = strtotime('6 months ago');
// Get the epoch timestamp for right now
$range_end   = time();

$submitted_date = strtotime($_POST['yr'] . '-' . 
                            $_POST['mo'] . '-' . 
                            $_POST['dy']);

if (($range_start > $submitted_date) || ($range_end < $submitted_date)) {
    $errors[] = 'Please choose a date less than six months old.';
}
?>
  
  








Related examples in the same category

1.Calculating a date interval with strtotime()
2.int strtotime ( string time [, int now] ) converts strings to a timestamp
3.Using strtotime()
4.Using strtotime() with a starting epoch timestamp
5.Find the First monday on or after November 1, 2008
6.Find weekday
7.Finding the Date for a Weekday
8.Getting the Day and Week of the Year
9.If PHP is unable to convert your string into a timestamp, it will return -1.
10.Obtaining the Difference Between Two Dates
11.Subtracts a year from a given timestamp