Link to home
Start Free TrialLog in
Avatar of erikTsomik
erikTsomikFlag for United States of America

asked on

sql current date based of on the time zone

I have the query that looking into a date. the sql looks at the condition where date <= 'date from the database'. I have 1 client that located in California (PST) and when he look at the recordset is nbot working for him. How would I say in sql to look at the localTime.

FOr example, the database is set to hjave startDate <= '7/1/2015' if I am in the east cost 12:00AM it is 7/2/12015 but in the west cost it is 9:00PM
Avatar of Phil Davidson
Phil Davidson
Flag of United States of America image

I would try this:

select * from table where date <= CONVERT (date, SYSDATETIMEOFFSET())

Open in new window


You may want to read this:

https://msdn.microsoft.com/en-us/library/bb677334.aspx
Avatar of Vitor Montalvão
You might need to change the data type to datetimeoffset to store the time zone.
Avatar of erikTsomik

ASKER

Thank you Victor. But I not sure. For example the data get stored in Eastern Standard time, and applied in Pacific Time
Datetimeoffset allows you to save a data with his time zone.
You can confirm data by running the following query (check the last 6 characters from the 2nd column):
select SYSDATETIME(), SYSDATETIMEOFFSET()

Open in new window

How Would I interpret that on the other side, So if the time is EST and the client want to apply and check the date on PST zone how would the query looks like
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial