March 10, 2005 at 12:51 am
Hi Guys,
Is there any way to convert date format from UTC to PST ???
It's urgent...
Thanks and Regards
Ashu Garg
March 10, 2005 at 12:57 am
I believe the time difference is -8 hours so try this...
DATEADD(hh,-8,yourUTCdatetime)
--Jeff Moden
Change is inevitable... Change for the better is not.
March 10, 2005 at 2:14 am
Thanks Jeff,
But the problem is that PST is adjusted due to "Day Light Saving" system and hence the difference between GMT and PST will vary by 1 hour.
Please tell me how to handle this problem in this case.
Thanks
Ashu
March 10, 2005 at 6:57 am
This was written for Eastern Time Zone and does take into account the diff between ST and DST
CREATE PROCEDURE Convrt_GMT_To_Eastern
@DateIn datetime,
@DateOut datetime OUTPUT
AS
--This Code Converts GMT to Local Time
Declare @DateUse datetime
Declare @TimeChg VARCHAR(20)
Declare @DayVal NUMERIC
Declare @GMT datetime
DECLARE @DiffDST int,
@DiffST int
SET @DiffDST = -4
SET @DiffST = -5
SET @DateUse = @DateIn --Get Current DateTime
If Month(@DateUse) >= 10 --Check To See if Date is Oct, Nov, or Dec
BEGIN
Set @TimeChg = '10/31/' + Cast(Year(@DateUse) as varchar) --Use Oct 31 as strt Point
END
ELSE
Set @TimeChg = '4/1/' + Cast(Year(@DateUse) as varchar) --Use April 1 as start point
Set @DayVal = DatePart(weekday,@TimeChg) --Is the Start Point a Sunday
If @DayVal <> 1 --If Not then when is the proper Time Change Sunday
If DatePart(m,@TimeChg) = 4 --Is the base the April Value
Begin
Set @TimeChg = DateAdd(d,8 - @DayVal,@TimeChg) --For April it is the first Sunday of the Month
Set @TimeChg = DateAdd(hh,7, @TimeChg)
End
Else
BEGIN
Set @TimeChg = DateAdd(d,-@DayVal + 1,@TimeChg) --For Oct it is the last Sunday of the Month
Set @TimeChg = DateAdd(hh,6, @TimeChg)
END
If DatePart(m,@TimeChg) = 4 --If Time Change is Based on April
Begin
If @DateUse < @TimeChg --If DateUse < The Time Change Date & Time
Begin
Set @DateUse = DateAdd(hh,@DiffST,@DateUse) --GMT 5 hours ahead for EASTERN Daylight Savings
End
Else
Set @DateUse = DateAdd(hh,@DiffDST,@DateUse) --GMT 4 hours ahead for EASTERN Standard
End
Else
If @DateUse < @TimeChg --If DateUse < The Time Change Date & Time
Begin
Set @DateUse = DateAdd(hh,@DiffDST,@DateUse) --GMT 4 hours ahead for EASTERN Standard
End
Else
Set @DateUse = DateAdd(hh,@DiffST,@DateUse) --GMT 5 hours ahead for EASTERN Daylight Savings
Set @DateOut = @DateUse --Date time to eastern TZ
GO
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply