Forum


HomeHomePremiumPremiumDevelopmentDevelopmentTime Zone in 6.X and upTime Zone in 6.X and up
Previous
 
Next
New Post
12/16/2013 5:05 AM
 

We have a custom module that uses the previous method of time zone storage to display content to users. We have upgraded to a newer versions of DNN however I am unable to find where the individual users timezone is stored in a usable manner. Right now we can simply use the the old method of  + or - in minutes.

 
New Post
12/16/2013 5:57 AM
 

Mark,

Assuming you are doing this from inside your module view (PortalModuleBase), you can get the user's local time based on the server time like this:

var tz = UserInfo.Profile.PreferredTimeZone;
DateTime userlocalTime = DateTime.UtcNow.AddHours(tz.BaseUtcOffset.Hours);

Let me know if this is what you are looking for.

 
New Post
12/16/2013 6:55 AM
 

Sorry I missed that detail, we have an external application that is also using the data so we want to determine the time zone for the user ideally through data available in the database as before.

 
New Post
12/16/2013 10:22 AM
 

If you must go directly through the database, it seems like you need to get the timezone string from the UserProfile table like:

SELECT TOP 1 up.PropertyValue 
FROM UserProfile up JOIN ProfilePropertyDefinition pdef ON up.PropertyDefinitionID = pdef.PropertyDefinitionID
WHERE up.UserID = 1 AND pdef.PortalID = 0 
AND pdef.PropertyName = 'PreferredTimeZone'

This will give you something like 'Pacific Standard Time' which you will have to map (or create a lookup table) to get the GMT offset of that timezone string.  Then subtract the hours from the GETUTCDATE().

 
New Post
12/17/2013 10:07 AM
 

Where does DNN map the text value of the timezone field to? Is this a web service or a local file?

 
Previous
 
Next
HomeHomePremiumPremiumDevelopmentDevelopmentTime Zone in 6.X and upTime Zone in 6.X and up



Try FREE
30 days money back guaranteed