Jump to content

comparing 2 time stamp dates


jenny kaur

Recommended Posts

i need to know how to display a message if a certain day "2006-05-28" is in a date range input via a html form.

[code]$start_date="2006-05-20";
$end_date="2006-05-29";
$start = strtotime("$start_date");
$end = strtotime("$end_date"); [/code]

how would i display a message in the case above, i.e, your date selection includes "2006-05-28" which is a special day!

however if the date is from 2006-05-29 to 2006-05-30, there should be no message. only if the date range features the 28th!


please help,
cheers!
Link to comment
https://forums.phpfreaks.com/topic/5404-comparing-2-time-stamp-dates/
Share on other sites

you're on the right track. now you just need to compare the date with the range.
[code]
$special_date = "2006-05-28";

$start_date="2006-05-20";
$end_date="2006-05-29";
$start = strtotime("$start_date");
$end = strtotime("$end_date");
$special = strtotime($special_date);

if ($special>=$start && $special<=$end)
{
   echo 'thats a special date!';
}
[/code]


cheers
Mark
It will also work without the strtotime conversions

[code]$special_date = "2006-05-28";

$start_date="2006-05-20";
$end_date="2006-05-29";

if ($special_date>=$start_date && $special_date<=$end_date)
{
   echo 'thats a special date!';
}[/code]

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.