Jump to content

Archived

This topic is now archived and is closed to further replies.

rune_sm

Time question??

Recommended Posts

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:


[code]

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

[/code]

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

  - thanx

Share this post


Link to post
Share on other sites
Always store date in date format (yyyy-mm-dd) and date-time in datetime format.  That will make all comparisons vastly simpler.  You can [i]display[/i] date and time in any form you choose by using the right date() parameters.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[quote author=rune_sm link=topic=106317.msg425028#msg425028 date=1156975121]
How do I compare these 2 dates and see if the first datetime is before or after the current time?
[/quote]

IF ...

[code]<?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";
?>[/code]

Share this post


Link to post
Share on other sites

×

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.