OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
Re: date comparison query

From: Halász Sándor (hsvtbbs.net)
Date: Sat Mar 17 2012 - 01:00:40 CDT


>>>> 2012/03/16 13:30 -0400, Simon Wilkinson >>>>
My query for this is as follows: select * from table where table.date1 -
table.date2 between 28425600 and 29030400;
<<<<<<<<
I would not count on that subtraction s yielding a meaningful number: the types are not Unix timestamps. I would use TIMESTAMPDIFF, with a good unit.

 From the downloaded help file:

>>>>
Date arithmetic also can be performed using INTERVAL together with the <file:///C:/Program%20Files/MySQL/MySQL%20Server%205.1/HELP/functions.html#operator_plus>+ or <file:///C:/Program%20Files/MySQL/MySQL%20Server%205.1/HELP/functions.html#operator_minus>- operator:

date + INTERVAL expr unit
date - INTERVAL expr unit

<<<<

but subtracting timestamp from timestamp hoping for a while (interval) is not mentioned.
If you want the subtraction to work, make them big integers and use UNIX_TIMESTAMP and FROM_UNIXTIME. See
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql