Get the UTC DateTime of a SharePoint Field using Client Object Model C#

Following is just a sample to get the current site’s last modified date in UTC. You can apply the same to any DateTime fields in SharePoint. Here, SharePoint itself returns the DateTime in UTC as per its regional setting.
ClientContext ctx = new ClientContext(weburl);
ctx.Credentials = new SharePointOnlineCredentials(userName, passWord); 
RegionalSettings regionalSettings = ctx.Web.RegionalSettings;

ClientResult<DateTime> utcTime = regionalSettings.TimeZone.LocalTimeToUTC(ctx.Web.LastItemModifiedDate);

ctx.ExecuteQuery();

utcTime.Value is your DateTime in UTC.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s