rhyno Posted February 14, 2008 Share Posted February 14, 2008 I need to figure out if an entered date has occured in the past... eg) I want to meet with you on this date: 2008/02/05 but todays date is 2008/02/12 would you do something like this? if($_SESSION['contact_array']['meeting_date'] <= getdate()){ then no meeting; }else { proceed with the meeting;} Link to comment https://forums.phpfreaks.com/topic/91128-how-would-you/ Share on other sites More sharing options...
revraz Posted February 14, 2008 Share Posted February 14, 2008 Did you try it? Link to comment https://forums.phpfreaks.com/topic/91128-how-would-you/#findComment-467037 Share on other sites More sharing options...
rhodesa Posted February 14, 2008 Share Posted February 14, 2008 Those values are strings, and won't really compare. I would recommend working with timestamps <?php $_SESSION['contact_array']['meeting_date'] = strtotime('2/14/2008 1:00PM EST'); //This is a timestamp of 1203012000 if($_SESSION['contact_array']['meeting_date'] < time()){ //time() returns the current time as a timestamp //then no meeting; }else { //proceed with the meeting } ?> Link to comment https://forums.phpfreaks.com/topic/91128-how-would-you/#findComment-467045 Share on other sites More sharing options...
rhyno Posted February 14, 2008 Author Share Posted February 14, 2008 Yes i did and it appears to work. But was looking for a better way to do it. Thank you rhodesa. I will incorporate that into my script. Link to comment https://forums.phpfreaks.com/topic/91128-how-would-you/#findComment-467058 Share on other sites More sharing options...
rhodesa Posted February 14, 2008 Share Posted February 14, 2008 I always store dates as unix timestamps (both in PHP and in MySQL) because they are unformatted and timezone free. Someone else may be able to convince you otherwise though. Link to comment https://forums.phpfreaks.com/topic/91128-how-would-you/#findComment-467061 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.