Showing posts with label eastern. Show all posts
Showing posts with label eastern. Show all posts

Sunday, March 11, 2012

Convert Time

Hi,

Hopefully this is an easy one. I need a function to call from my page footer that takes the NOW date/time value and converts it from Eastern Standard Time to Mountain Standard Time. (My server is on EST time and my users are all on MST time) Of course the function needs to handle daylight savings as well.

thanks!

Why don't you just subtract two hours from the NOW date/time value to get MST.....

Regardless of where your server is, you should be able to convert the time value to any timezone in the world.

|||

That would work until daylight savings...then it's 3 hours difference. I was really hoping to get a custom function from someone...Thx

|||

So you're saying that NOW doesn't adjust for daylight savings?

|||

I'm saying the following:

If NOW is 2pm EST then MST is 12PM ( subtracting 2 hours from EST will work)

When daylight savings kicks in then NOW is 3pm EST and MST is still 12pm (subtracting 2 hours from EST give me 1pm which is incorrect.)

When I say MST I mean arizona time which does not change for daylight savings.

Hope that makes sense..

|||

Yes that makes sense. After a brief research of the forums and google, I've turned up empty handed. Hopefully someone else knows how to do it.

I am assuming that you can't simply change your server's time to MST.

|||

R.K.S. wrote:

I'm saying the following:

If NOW is 2pm EST then MST is 12PM ( subtracting 2 hours from EST will work)

When daylight savings kicks in then NOW is 3pm EST and MST is still 12pm (subtracting 2 hours from EST give me 1pm which is incorrect.)

When I say MST I mean arizona time which does not change for daylight savings.

Hope that makes sense..

You are not looking for DateTime but TimeZone there are only work around solutions but coming in VS2008 try the thread below for your options.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1860968&SiteID=1

|||

Thanks Caddre, Not the answer i was hoping for but at least i know i wasn't overlooking something simple.

What about this: I already have a function written in C# that will do the conversion. Can't i call a custom function like this in a page footer? Can the custom function exist in an assembly or in the custom code window...

Thx

|||

The Report properties includes code box what I don't know is if you can run it in a footer, you could also check the ReportViewer control it may have a way to use .NET code much easier than normal reports.

|||

If anyone is interested you can use this function to convert to whatever local time your users are on (assuming all your users are on a single timezone) So below, my server is EST and my users are all on MST

Public Shared Function AdjustDateTime(ByVal dt as DateTime)

Dim tz as System.TimeZone
tz = System.TimeZone.CurrentTimeZone

Dim utc as System.DateTime
utc = tz.ToUniversalTime(dt)

'Convert EST to MST
if Not tz.IsDaylightSavingTime(dt) then
AdjustDateTime =utc.ToLocalTime().AddHours(-2)
else
AdjustDateTime =utc.ToLocalTime().AddHours(-3)
end if

End Function

Convert Time

Hi,

Hopefully this is an easy one. I need a function to call from my page footer that takes the NOW date/time value and converts it from Eastern Standard Time to Mountain Standard Time. (My server is on EST time and my users are all on MST time) Of course the function needs to handle daylight savings as well.

thanks!

Why don't you just subtract two hours from the NOW date/time value to get MST.....

Regardless of where your server is, you should be able to convert the time value to any timezone in the world.

|||

That would work until daylight savings...then it's 3 hours difference. I was really hoping to get a custom function from someone...Thx

|||

So you're saying that NOW doesn't adjust for daylight savings?

|||

I'm saying the following:

If NOW is 2pm EST then MST is 12PM ( subtracting 2 hours from EST will work)

When daylight savings kicks in then NOW is 3pm EST and MST is still 12pm (subtracting 2 hours from EST give me 1pm which is incorrect.)

When I say MST I mean arizona time which does not change for daylight savings.

Hope that makes sense..

|||

Yes that makes sense. After a brief research of the forums and google, I've turned up empty handed. Hopefully someone else knows how to do it.

I am assuming that you can't simply change your server's time to MST.

|||

R.K.S. wrote:

I'm saying the following:

If NOW is 2pm EST then MST is 12PM ( subtracting 2 hours from EST will work)

When daylight savings kicks in then NOW is 3pm EST and MST is still 12pm (subtracting 2 hours from EST give me 1pm which is incorrect.)

When I say MST I mean arizona time which does not change for daylight savings.

Hope that makes sense..

You are not looking for DateTime but TimeZone there are only work around solutions but coming in VS2008 try the thread below for your options.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1860968&SiteID=1

|||

Thanks Caddre, Not the answer i was hoping for but at least i know i wasn't overlooking something simple.

What about this: I already have a function written in C# that will do the conversion. Can't i call a custom function like this in a page footer? Can the custom function exist in an assembly or in the custom code window...

Thx

|||

The Report properties includes code box what I don't know is if you can run it in a footer, you could also check the ReportViewer control it may have a way to use .NET code much easier than normal reports.

|||

If anyone is interested you can use this function to convert to whatever local time your users are on (assuming all your users are on a single timezone) So below, my server is EST and my users are all on MST

Public Shared Function AdjustDateTime(ByVal dt as DateTime)

Dim tz as System.TimeZone
tz = System.TimeZone.CurrentTimeZone

Dim utc as System.DateTime
utc = tz.ToUniversalTime(dt)

'Convert EST to MST
if Not tz.IsDaylightSavingTime(dt) then
AdjustDateTime =utc.ToLocalTime().AddHours(-2)
else
AdjustDateTime =utc.ToLocalTime().AddHours(-3)
end if

End Function