Virto Team Blog about Microsoft SharePoint
Blog covers SharePoint news, tips, and developments within the industry, along with popular topics about ASP.NET, Ajax, Silverlight, JQuery technologies.
Using and converting date, time and timezone in Microsoft Windows SharePoint Services 3.0

This topic includes many of the "how-to" and walk-through topics for time using and time zone functions in Microsoft Windows SharePoint Services 3.0.

Change the regional settings for a site
Get current time in SharePoint Designer workflow
Get the Coordinated Universal Time (UTC) in SharePoint Designer workflow
Get the custom predefined time in SharePoint Designer workflow
Convert Local Time to the Coordinated Universal Time (UTC) in SharePoint Designer workflow
Convert the Coordinated Universal Time (UTC) to Local Time in SharePoint Designer workflow
Get Current Time in Different Time Zones
Get string from DateTime with Time Zone information.
Get date time string with time zone information
Daylight savings not working right for SPGridView
Getting the type DateTime from SPListItemVersion
Set correct time zone
How to manually update the DST period for a time zone definition

Change the regional settings for a site

Do the following on each SharePoint site on which you want to change the default regional settings:
1.    Open the site on which you want to change the default regional settings.
2.    Click Site Settings in the Site Actions menu
 Note   On a site for which the Site Actions menu is customized, point to Site Settings, and then click the settings that you want to view.
3.    On the Site Settings page, under Site Administration, click Regional settings.
4.    On the Regional Settings page, select the settings that you want for this site, and then click OK.
Links:  
http://office.microsoft.com/en-us/sharepointtechnology/HA101038101033.aspx

Get current time in SharePoint Designer workflow

You will have trouble getting the current time in a SharePoint Designer workflow when testing against a date/time field of the current item, because SharePoint returns 12:00 AM as the time.

To get the current time, you can use “Set DateTime constant” activity from Virto SharePoint Workflow Activities Kit.

This activity allows setting DateTime constant Now to variable and you can use correct time in other workflow actions.

Get the Coordinated Universal Time (UTC) in SharePoint Designer workflow

SharePoint Designer workflow doesn’t allow getting the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).
To get the current time, you can use “Set DateTime constant” activity from Virto SharePoint Workflow Activities Kit.

This activity allows setting DateTime constant UtcNow to variable and you can use correct time in other workflow actions.

Get custom predefined time in SharePoint Designer workflow

SharePoint Designer workflow doesn’t allow getting the custom predefined time and time on this computer, expressed as the Coordinated Universal Time (UTC).
To get the custom predefined time, you can use “Set DateTime constant” activity from Virto SharePoint Workflow Activities Kit.

This activity allows setting Date Time constant: Now, Utc Now, Today, Yesterday, Tomorrow, Begin of this Week, End of this Week and etc. to variable.

The activity stores time constant to variable and you can use correct time in other workflow actions. The tables below shows all constant, description and sample result if current time is 12 February 2010 16:20 (UTC+2:00).

 

.style1 { border: 1px solid #666666; }

Name Description Example
Now The current date and time on this computer, expressed as the local time. 12 February 2010 16:20
UtcNow The current date and time on this computer, expressed as the Coordinated Universal Time (UTC). 12 February 2010 15:20
Today Current date. 12 February 2010 00:00
Yesterday Yesterday date. 11 February 2010 00:00
Tomorrow Tomorrow date 13 February 2010 00:00
Begin of this week Begin of this Week
Note: Sunday is the first day of the week.
7 February 2010 00:00
End of this week End of this Week
Note: Saturday is the last day of the week
13 February 2010 23:59
Begin on this month Begin on the month 1 February 2010 00:00
End on this month End on this month. 28 February 2010 23:59
Begin of this year Begin of this year 1 January 2010 00:00
End of this year End of this year 31 December 2010 23:59

SharePoint Workflow Designer Phrase
Set DateTime constant Now to variable.

Parameter - Now

Description 

One of date time constant:
•    Now
•    UtcNow
•    Today
•    Yesterday
•    Tomorrow
•    Begin of this Week
•    End of this Week
•    Begin of this Month
•    End of this Month
•    Begin of this Year
•    End of this Year

Convert Local Time to the Coordinated Universal Time (UTC) in SharePoint Designer workflow

To convert local time to the UTC, you can use “Converts Date from Local Time to UTC” activity from Virto SharePoint Workflow Activities Kit.
This activity allows converting the value of the current DateTime variable from local time in specified Time Zone to Coordinated Universal Time (UTC).

You can specify custom time zone or use time zone from current site.

SharePoint Workflow Designer Phrase
Converts local time from Local Time in [Current Site] time zone to UTC and store result in utc_time.

 

Parameter Description
local_time Date Time variable.
[Current Site] Optional. Time zone. Default value is current site time zone, but you can select you custom time zone.

 

Convert the Coordinated Universal Time (UTC) to Local Time in SharePoint Designer workflow

To convert UTC time to the Local Time, you can use “Converts Date from UTC to Local Time” activity from Virto SharePoint Workflow Activities Kit.
This activity allows converting the value of the current DateTime variable from to Coordinated Universal Time (UTC) to local time in specified Time Zone.

 
You can specify custom time zone or use time zone from current site.

SharePoint Workflow Designer Phrase
Converts utc time from UTC to time zone in [Current Site] time zone and store result in utc_time.
Parameters

Parameter Description
local_time Date Time variable.
[Current Site] Optional. Time zone. Default value is current site time zone, but you can select you custom time zone.

Get Current Time in Different Time Zones

To convert UTC time to the Local Time, you can use “Set Date constant” and “Converts DateTime from UTC to Local Time” activities from Virto SharePoint Workflow Activities Kit.
You should call “Set DateTime constant” activity and store UTC time to variable, then call “Converts DateTime from UTC to Local Time” activity to convert UTC time to local time. See screenshot below.

Get string from DateTime with Time Zone information.

To get string from Date Time with Time Zone information you can use “Convert DateTime to Text” activity from Virto SharePoint Workflow Activities Kit.
If pass “MM/dd/yyyy hh:mm:ss (zzz)” as format, activity will store “02.16.2010 02:33:34 (-05:00)” to text variable.

Useful links for describing time format strings:

Standard Date and Time Format Strings - http://msdn.microsoft.com/en-us/library/az4se3k1.aspx
Custom Date and Time Format Strings - http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Get date time string with time zone information

http://www.endusersharepoint.com/2010/01/15/sharepoint-workflow-time-zones/

Daylight savings not working right for SPGridView

http://wiki.bittercoder.com/%28S%28rmsmgt55gw13n4ixnd32kznj%29%29/Default.aspx?Page=DatesNotWorkingWithDSTInSPGridView&Code=1&AspxAutoDetectCookieSupport=1

Getting the type DateTime from SPListItemVersion

If you are using the Versions property of the SPListItem class to return the collection of versions for a list item, you should know that all time SPListItemVersion properties would be returned in UTC format. You should correctly convert them to the current time zone. To do this use SPTimeZone .UTCToLocalTime method to retrieve the current local date and time. The code shows how to compare two dates:
/ / First get the current SPTimeZone of SPWeb:
SPTimeZone timeZone = web.RegionalSettings.TimeZone;
/ / Convert date and time in local:
DateTime localDT = timeZone.UTCToLocalTime (previousDate);
if (newDate! = localDT)
(
    ...
)

Links:
http://moss.blog.ru/52286211.html

Set correct time zone

The link below shows solution for requirement to staple a feature to site templates so that despite the server living in Perth, east coast users would have their time-zone set correctly for the site they were creating.
http://www.sharepointdevwiki.com/display/public/TimeZones

How to update manually the DST period for a time zone definition

This link below describes how to update manually the daylight saving time (DST) period for a time zone definition in Microsoft Windows SharePoint Services 3.0 and in Microsoft Windows SharePoint Services 2.0 by modifying the Timezone.xml file. Windows SharePoint Services uses the Timezone.xml file to store time zone information. The Timezone.xml file includes the start date and time for daylight saving time and for standard time for a specific time zone.
http://support.microsoft.com/default.aspx/kb/888253


Posted 17 Feb 2010 1:50 AM by Oleg [Virtosoftware]
Filed under: , , , ,