rune_sm Posted August 30, 2006 Share Posted August 30, 2006 Hey EveryoneI want to make some code, that evaluates whether or not a given date and time is before or after the current date and timeI 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 Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 30, 2006 Share Posted August 30, 2006 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. Quote Link to comment Share on other sites More sharing options...
rune_sm Posted August 30, 2006 Author Share Posted August 30, 2006 Ok... So if I have this datetime: 1983-03-01 21:30:15 And the current datetime is: 2006-08-30 23:57:10How do I compare these 2 dates and see if the first datetime is before or after the current time? Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 30, 2006 Share Posted August 30, 2006 [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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.