I need to adjust three queries for a specific day-part to accomodate a different time zone. These queries pull transaction data from the previous day, a date range, and the current day. The server time is GMT and the queries currently work fine for pulling the transaction data based on the GMT server time. The day starts at 00:00 GMT of course, a calendar day based on server time. However, I need the queries to start the day at 12:00 GMT, not 00:00 GMT. The queries are below (the data type is datetime for the TransactionDate field):
Query 1
This query pulls a transaction summary for a particular client from the previous day, the WHERE clause of the query is as follows:
WHERE TransactionDate >= DateAdd(DD, DateDiff(DD, 0, GETDATE())-1, 0) AND TransactionDate < DateAdd(DD, DateDiff(DD, 0, GETDATE()), 0)
Query 2
This query has two date parameters and provides the same transaction data for the date range provided. The WHERE clause of the query is as follows:
WHERE TransactionDate BETWEEN @StartDateParam AND @EndDateParam
Query 3
The last query pulls a transaction summary for a specific client for the current day, the WHERE clause of the query is as follows:
WHERE TransactionDate >= CONVERT(CHAR(10),GETDATE(),120)
Again, these queries work fine for the current GMT server time. Can someone provide me with the right way to adjust the time element of the datetime field in each of these queries so the dayparts start at 15:00 GMT instead of the current 00:00 GMT start time.
Thanks in advance for your help.
(Rewritten from comments.)
I suggest you queries with either just a start part or the second version.
Just make sure you pass in the right values for
StartDateParamandEndDateParamthat are appropriate for the time zone you’re interested in. You don’t need to do all the conversions in the query, do you?Also note that “between” is annoyingly inclusive of the end point… it’s a pain for things like DATETIME fields, where you really want to say
start <= datetime < end…