Jump to content

Time question??


rune_sm

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
Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.