mikey3521 Posted June 20, 2007 Share Posted June 20, 2007 Hello, I'm working on a community site and have a question on how to-do the following. I want to grab a date from the database, then see if its 5 days or less away... so what i want todo is... select `date` from `users` where `username` = 'mike' if (`date` is... 5days or less away from today... then) { echo "Event Is Soon"; } else { } thoughts? Im not quite sure how to compre the date to todays date, and then calculate if its 5 days or less away... I should also mention the date field in the database returns this : 6/19/1984 Link to comment https://forums.phpfreaks.com/topic/56469-mysql-comparedates/ Share on other sites More sharing options...
The Little Guy Posted June 20, 2007 Share Posted June 20, 2007 Something similar to this (this is shortened): <?php $myDate = '6/19/1984'; // From DB list($cmonth,$cday,$cyear) = date("j/m/Y"); // Current Date list($month,$day,$year) = explode("/",$myDate); $diff = $cday - $day; if($diff < 6){ echo 'Less than 5 days left!'; } ?> Link to comment https://forums.phpfreaks.com/topic/56469-mysql-comparedates/#findComment-278893 Share on other sites More sharing options...
mikey3521 Posted June 21, 2007 Author Share Posted June 21, 2007 How would I do this but only in one direction, as in.. if the date hasn't come yet & its within 5 days.. that way im not getting bad info. Cause if the date was yesterday its past.. but its still smaller then 5.. but i don't want it to show past dates.. only today and upcomming Link to comment https://forums.phpfreaks.com/topic/56469-mysql-comparedates/#findComment-278996 Share on other sites More sharing options...
teng84 Posted June 21, 2007 Share Posted June 21, 2007 select `date` from `users` where `username` = 'mike' and `date`=>now() Link to comment https://forums.phpfreaks.com/topic/56469-mysql-comparedates/#findComment-279003 Share on other sites More sharing options...
teng84 Posted June 21, 2007 Share Posted June 21, 2007 oppps select `date` from `users` where `username` = 'mike' and `date`>=now() and wait the date should not be use for field name try something else date_xxx ya know ASTIG!! Link to comment https://forums.phpfreaks.com/topic/56469-mysql-comparedates/#findComment-279005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.