Eggzorcist Posted August 18, 2009 Share Posted August 18, 2009 I've always had extreme trouble comparing dates or times. For the application I'm currently building I need to be able to make a sql query which will compare the date and time. So with this query "SELECT * FROM events WHERE user = '".$_SESSION['USER']."'"; I want to add a AND statement which will check the sql field "fromslashes" (which for eg. is set like "08/03/2009" format) and will make sure that that date is 5 days later than the current date that it is now. So it only displays if that day is 5 days later than todays date or earlier. How would I be going about to form this statement? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/170843-trouble-with-comparing-time-differences/ Share on other sites More sharing options...
taquitosensei Posted August 18, 2009 Share Posted August 18, 2009 you should always use the datetime data type for dates. You can then change the format in your query if you need to. with addslashes as a datetime select * from events where user='".$_SESSION['USER']."' and addslashes between '".date("Y-m-d H:i:s")."' and '".date("Y-m-d H:i:s", strtotime("+ 5 days"))."'"; Quote Link to comment https://forums.phpfreaks.com/topic/170843-trouble-with-comparing-time-differences/#findComment-901023 Share on other sites More sharing options...
Eggzorcist Posted August 18, 2009 Author Share Posted August 18, 2009 I am currently using the dates datatype for that field. I don't really understand this query, why are we addslahes between? and I don't see how we are comparing the field "fromslahes" to the current date + 5. shoudn't it be some like: fromslahes > ".date("Y-m-d H:i:s", strtotime("+ 5 days"))."' or something alike? I'm a bit confused... Quote Link to comment https://forums.phpfreaks.com/topic/170843-trouble-with-comparing-time-differences/#findComment-901027 Share on other sites More sharing options...
Eggzorcist Posted August 18, 2009 Author Share Posted August 18, 2009 Does anyone know? Quote Link to comment https://forums.phpfreaks.com/topic/170843-trouble-with-comparing-time-differences/#findComment-901122 Share on other sites More sharing options...
taquitosensei Posted August 18, 2009 Share Posted August 18, 2009 it was supposed to be "fromslashes". I made a typo. It gets all the records in "fromslashes" that are between today and today + 5 days Quote Link to comment https://forums.phpfreaks.com/topic/170843-trouble-with-comparing-time-differences/#findComment-901361 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.