Jump to content


Photo

comparing 2 time stamp dates


  • Please log in to reply
2 replies to this topic

#1 jenny kaur

jenny kaur
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 March 2006 - 08:42 AM

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.

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

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!

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 21 March 2006 - 08:55 AM

you're on the right track. now you just need to compare the date with the range.
$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!';
}


cheers
Mark
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 21 March 2006 - 08:33 PM

It will also work without the strtotime conversions

$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!';
}

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users