Jump to content


Photo

Time question??


  • Please log in to reply
3 replies to this topic

#1 rune_sm

rune_sm
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 30 August 2006 - 09:47 PM

Hey Everyone

I want to make some code, that evaluates whether or not a given date and time is before or after the current date and time
I have a date and time in my database (what is the best format to store this in?), and then compare it to the current date and time and see if the database date and time has passed the current date and time.

Something like this:



if(currDate =< DBdate)
{
   if(currtime =< DBtime)
   {
      print('the ime hasn't come yet');
   }
}
else
{
    print('the time has passed');
}


How do I do this. I have read the time FAQ but can't really figure it out...??

  - thanx

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 August 2006 - 09:54 PM

Always store date in date format (yyyy-mm-dd) and date-time in datetime format.  That will make all comparisons vastly simpler.  You can display date and time in any form you choose by using the right date() parameters.
Legend has it that reading the manual never killed anyone.
My site

#3 rune_sm

rune_sm
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 30 August 2006 - 09:58 PM

Ok... So if I have  this datetime:    1983-03-01 21:30:15
      And the current datetime is:  2006-08-30 23:57:10


How do I compare these 2 dates and see if the first datetime is before or after the current time?



#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 August 2006 - 10:42 PM

How do I compare these 2 dates and see if the first datetime is before or after the current time?


IF ...

<?php
$date_from_db = "1999-12-31 23:59 59";
$date_now = date("Y-m-d H:i:s");

if ($date_now>$date_from_db) {
    echo "Welcome to the 21st century"; // or any other message
} else {
    echo "Still in the 20th century";
?>

Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users