Forum Moderators: open

Message Too Old, No Replies

MySQL datetime and timestamp units

         

wesg

2:04 am on Jan 12, 2009 (gmt 0)

10+ Year Member



I'm writing a PHP application that uses MySQL on the back end to work with dates. One of the functions is showing events that are less than xx days in the future. RIght now I can't seem to get the numbers right.

This is the code I'm using:

(current - DATE_ADD( NOW( ) , INTERVAL 0 HOUR ) >= 86400*30 days)

I'm using the interval function to compensate for server time zones. Current is the datetime field in my database. I can't seem to figure out what the unit is for the returned calculation. When I find the difference in the dates, the numbers don't add up.

What can I do differently to calculate the time difference between two dates (the datetime field and the current time)?

wesg

3:01 am on Jan 12, 2009 (gmt 0)

10+ Year Member



I've fashioned a solution using TO_DAYS(). That ought to hold it.

coopster

10:25 pm on Jan 14, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Glad you got it sorted.

showing events that are less than xx days in the future

SELECT current FROM myTable WHERE current BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL 30 DAY;