I need to be able to query results from my table from yesterday at 7:01AM through today at 7:00AM. basically a full says worth of data. im not having any luck doing that. Any help would be great
What sort of column data type has the date/time? At least on MySQL I have many such queries. Some applications operate on UnixEpoc date/time tracking, so it was necessary to calculate the correct numbers in UnixEpoc format. Other web applications use a traditional datetime column datatype. so all that was necessary was to build the correct datetime strings to go from midnight one day to midnight the next day.
Assuming your date/time is in unencoded storage, query it along the lines of:
Code:
WHERE colname BETWEEN '2012-01-01 00:00:00' AND '2012-01-01 23:59:59'
Or if it is encoded, then you need to convert from the unencoded format to what ever encoding method is in use.
What specifically are you asking? Calculating an accurate date for "yesterday" taking into account "Leap Years" and "Second Tuesday's of the Week" situations?
I rely on the Open Object Rexx (ooRexx) programming language, with the built-in date/time classes. Much easier if I do not code date/time math code on my own! My MySQL queries I code in Bash, and Bash executes an ooRexx script when it has need to execute a "between" type query.
In my mind, you are looking for a trust worthy date/time class.
Yes i understand that. here is my where clause and it works if its run at 7AM everyday, but if its run at 10am then i only get data from 10-10. but i always want data from 7-7
WHERE ReqDateTime between Cast(convert(varchar,getdate()-1, 101) As datetime) + '7:00:00' And Cast(convert(varchar,getdate(), 101) As datetime) + '6:59:59'
Yes i understand that. here is my where clause and it works if its run at 7AM everyday, but if its run at 10am then i only get data from 10-10. but i always want data from 7-7