Convert UTC Time to Pacific Time Query:crazy: – SQLServerCentral Forums (2024)

drodriguez-762178

SSCommitted

Points: 1795

More actions

April 17, 2009 at 3:45 pm

#133186

Anyone know of a function I can use to convert the UTC date/time field to Pacific Time? I know I can use dateadd to subtract the 8 hours, but I would like to know if there is a better way.

UTC Time

2009-04-17 21:44:10.717

Current Time

2009-04-17 14:44:10.717

Thanks,

Dave

arun.sas

SSChampion

Points: 11831

More actions

April 17, 2009 at 9:31 pm

#980116

Hi,

One of the way

Declare @abc TABLE

(

SLNO int,

UTC Datetime,

CON_DATE as (dateadd(hh,-8,UTC))

)

insert into @abc(slno,UTC) values(1,Getdate())

select * from @abc

ARUN SAS

fayilt

Right there with Babe

Points: 727

More actions

April 18, 2009 at 5:35 am

#980162

CLR UDF will help you

April 18, 2009 at 10:32 pm

#980312

Knowing your time zone (Pacific) is a good start. But of course you also will probably want to account for whether daylight saving time is in effect, making the difference -7 hours rather than -8. If your server is set to the Pacific time you want (standard or daylight), you may use the DateDiff between getDate() and getUTCDate() as your offset, using DateAdd to apply it to your UTC time.

Declare @MyDateUTC datetime

Set @MyDateUTC = '2009-04-19 04:12'

select @MydateUTC as MyDateUTC

,DateAdd(hh,DATEDIFF(hh, GetUtcDate(), GetDate()), @MyDateUTC) as MyDatePacific

MyDateUTC MyDatePacific

----------------------- -----------------------

2009-04-19 04:12:00.000 2009-04-18 21:12:00.000

(1 row(s) affected)

Of course, the current difference (-7) may not be valid if you're looking at a date from February, for instance. For an application that looks at historic times and needs to convert any from UTC to Pacific Time, I'd think you'll need a table of the start and end dates for Daylight Saving Time to know whether it's -7 hours or -8 hours. A web search should turn up the basic data for you. Depending on how far back you go, the dates and rules for determining the dates Daylight Saving Time started and ended have changed many times over the years.

Goldie Lesser

SSCertifiable

Points: 6155

More actions

April 20, 2009 at 5:57 pm

#981126

drodriguez (4/17/2009)

Anyone know of a function I can use to convert the UTC date/time field to Pacific Time? I know I can use dateadd to subtract the 8 hours, but I would like to know if there is a better way.

UTC Time

2009-04-17 21:44:10.717

Current Time

2009-04-17 14:44:10.717

Thanks,

Dave

If you do not need exact times in your data, and if you are only ever converting from Pacific to UTC and not other time zones, then you can use the method John suggested.

For better accuracy, you can create a table in your database which stores the time zones and when each country switches to daylight savings. You can download the applicable functions and data from The Code Project http://www.codeproject.com/KB/database/ConvertUTCToLocal.aspx

Unfortunately, even this will not be accuarate for historic data, as countries change the daylight savings dates each year.

In SQL Server 2008, there is a new datatype called DateTimeOffset which stores the offset together with the date, so that dates can be converted accurately.

kylemwhite

SSC Enthusiast

Points: 190

More actions

April 20, 2009 at 11:19 pm

#981203

If you are only concerned with dates after 2006, the Microsoft functions will probably be accurate. If, however, you have historical data, then do not trust the Microsoft functions. It gets tricky. I have written about this subject on my blog: Kyle's Technobabble.

Goldie Lesser

SSCertifiable

Points: 6155

More actions

April 21, 2009 at 7:45 am

#981428

kylemwhite (4/20/2009)

If you are only concerned with dates after 2006, the Microsoft functions will probably be accurate. If, however, you have historical data, then do not trust the Microsoft functions. It gets tricky. I have written about this subject on my blog: Kyle's Technobabble.

Which Microsoft functions are you talking about?

drodriguez-762178

SSCommitted

Points: 1795

More actions

April 21, 2009 at 8:55 am

#981502

I figured it out.

Thank you.

kylemwhite

SSC Enthusiast

Points: 190

More actions

April 21, 2009 at 9:48 am

#981565

Old Hand: I guess my post was a bit incomplete. I am referring to the TimeZone.ToUniversalTime() function in .Net. I've updated my blog post as well and also included the Java functions used (DateFormat.setTimeZone() and TimeZone.getTimeZone())

john.arnott

SSChampion

Points: 11882

More actions

April 21, 2009 at 9:50 am

#981570

drodriguez,

You say you figured it out. Please share your solution so others can learn from it. Thanks!!

drodriguez-762178

SSCommitted

Points: 1795

More actions

April 21, 2009 at 9:53 am

#981574

I subtracted 8 hours using a dateadd(hh,-8, column).

john.arnott

SSChampion

Points: 11882

More actions

April 21, 2009 at 10:01 am

#981582

drodriguez (4/21/2009)

I subtracted 8 hours using a dateadd(hh,-8, column).

So this was just for data with dates before March 8 this year, after which it would be 7 hours.... OK.

fayilt

Right there with Babe

Points: 727

More actions

April 23, 2009 at 12:12 pm

#983174

I hope, that this is the temporary solution, otherwise you have to change your code 2 times a year. Moreover, you can not get valid date in the past.

drodriguez-762178

SSCommitted

Points: 1795

More actions

April 23, 2009 at 12:25 pm

#983184

Do you have a better solutions?

-Dave

john.arnott

SSChampion

Points: 11882

More actions

April 23, 2009 at 12:50 pm

#983201

drodriguez (4/23/2009)

Do you have a better solutions?

-Dave

Well..... Yes.

Take another look at my suggestion above. Look at Goldie's first post. Consider reading the link Kyle gave to his blog for information on the MS conversion function. This last may actually be your best bet, even if (or maybe because) it would be in the presentation of your data and not the SQL.

Convert UTC Time to Pacific Time Query:crazy: – SQLServerCentral Forums (2024)

References

Top Articles
2006 FORD F-450 XL diesel for sale - Seattle, WA - craigslist
2018 Jeep Wrangler for sale - Spokane, WA - craigslist
Whas Golf Card
NOAA: National Oceanic & Atmospheric Administration hiring NOAA Commissioned Officer: Inter-Service Transfer in Spokane Valley, WA | LinkedIn
How to change your Android phone's default Google account
Hawkeye 2021 123Movies
Gore Videos Uncensored
Otis Department Of Corrections
San Diego Terminal 2 Parking Promo Code
THE 10 BEST River Retreats for 2024/2025
Tanger Outlets Sevierville Directory Map
Apnetv.con
Tribune Seymour
Whiskeytown Camera
Es.cvs.com/Otchs/Devoted
Evangeline Downs Racetrack Entries
Arboristsite Forum Chainsaw
SXSW Film & TV Alumni Releases – July & August 2024
Navy Female Prt Standards 30 34
24 Hour Drive Thru Car Wash Near Me
Adam4Adam Discount Codes
Craigslist Toy Hauler For Sale By Owner
R Personalfinance
Gia_Divine
Foxy Brown 2025
Christina Steele And Nathaniel Hadley Novel
Katie Sigmond Hot Pics
The Old Way Showtimes Near Regency Theatres Granada Hills
St Clair County Mi Mugshots
Cookie Clicker Advanced Method Unblocked
Urban Dictionary Fov
JVID Rina sauce set1
Miles City Montana Craigslist
Angel Haynes Dropbox
Miller Plonka Obituaries
Pioneer Library Overdrive
Log in or sign up to view
Ghid depunere declarație unică
Chadrad Swap Shop
Sf Bay Area Craigslist Com
Wake County Court Records | NorthCarolinaCourtRecords.us
A Small Traveling Suitcase Figgerits
Gas Prices In Henderson Kentucky
Go Upstate Mugshots Gaffney Sc
Edict Of Force Poe
Troy Gamefarm Prices
Raising Canes Franchise Cost
Jail View Sumter
Bill Manser Net Worth
Winta Zesu Net Worth
Stosh's Kolaches Photos
SF bay area cars & trucks "chevrolet 50" - craigslist
Latest Posts
Article information

Author: Dr. Pierre Goyette

Last Updated:

Views: 6362

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Dr. Pierre Goyette

Birthday: 1998-01-29

Address: Apt. 611 3357 Yong Plain, West Audra, IL 70053

Phone: +5819954278378

Job: Construction Director

Hobby: Embroidery, Creative writing, Shopping, Driving, Stand-up comedy, Coffee roasting, Scrapbooking

Introduction: My name is Dr. Pierre Goyette, I am a enchanting, powerful, jolly, rich, graceful, colorful, zany person who loves writing and wants to share my knowledge and understanding with you.