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
LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Phil DavidsonCommented:
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
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
You might need to change the data type to datetimeoffset to store the time zone.
0
erikTsomikSystem Architect, CF programmer Author Commented:
Thank you Victor. But I not sure. For example the data get stored in Eastern Standard time, and applied in Pacific Time
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Vitor MontalvãoMSSQL Senior EngineerCommented:
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

0
erikTsomikSystem Architect, CF programmer Author Commented:
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
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
You'll need to use the SWITCHOFFSET() function. Imagine that PST is -08:00 and EST is -04:00, then you should run similar to the following:
SELECT SYSDATETIMEOFFSET() AS PST, SWITCHOFFSET(SYSDATETIMEOFFSET(),'-04:00') AS EST

Open in new window

Just replace SYSDATETIMEOFFSET() with your datetime columname.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.