Jump to content

trouble with comparing time differences...


Eggzorcist

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/170843-trouble-with-comparing-time-differences/
Share on other sites

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"))."'"; 

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

Archived

This topic is now archived and is closed to further replies.

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