YYYY-MM-DDThh:mmTZD or
YYYY-MM-DDThh:mm:ssTZD
where,
- understandably YYYY being 4-digit year, MM for 2-digit month number, DD for day of month
- T stands for start of time.
- Following that denotes the time which could be "hh:mm" (hours-mins) or "hh:mm:ss" (hours-mins-seconds)
- Z indicates the Coordinated Universal Time (UTC)
Convert from DateTime to ISO8601 DateTime (C#):
DateTime date = DateTime.Now; string isoDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(date); |
When you are trying to insert or modify some DateTime fields to or from a SPListItem, you could use the code given above to format values into ISO 8601.
You can build the CAML query for the SPQuery object as shown below:
Example:
Note: Don't forget to add reference of Microsoft.SharePoint.Utilities in your class file before building your project.
Convert from ISO8601 to DateTime (C#):
DateTime date = DateTime.Parse("2010-06-15 00:00:00"); string sysDate = date.ToString("MM/dd/yyyy"); |
Note: In above example, the ISO DateTime string is converted to DateTime equivalent using DateTime.Parse method.
Also, incase you want to change the Site Collection date format:
- Go to "Site Settings" & navigate to "Modify All Site Settings"
- Click on Regional Settings under Site Administration
- Change the time zone. Save the changes.
2 comments:
Good post.
Thanx a lot :), I wasn't able update DateTime form field properly until i use CreateISO8601DateTimeFromSystemDateTime in ItemAdding event receiver.
Post a Comment