Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I've run into a strange problem with SharePoint Online.

When updating or creating entries in a list using the Client Object Model, the modified date on the affected list item seems to be stored with the wrong timezone.

Our Office 365 server is at UTC -7 (I assume it's probably on Redmond time, even if it's not actually physically there), and I am at UTC +1. If I create a record using C# on the server, the modified date is stored with the current date and time at UTC -7. However, if I store a record from the client using JavaScript, the record is stored with my current time, but is also at UTC -7!

e.g.

if current time        = 13:07 GMT
my local time          = 14:07 UTC +1
storing on the server  = 06:07 UTC -7
storing via the client = 14:07 UTC -7  (e.g. 8 hours in the future!)

I am not setting the modified date directly - I'm relying on SharePoint to track this information correctly.

My client script looks like this:

function addRow() {
    //Create a new record
    var context = SP.ClientContext.get_current();
    var extList = context.get_site().get_rootWeb().get_lists().getByTitle(options.listTitle);

    var itemCreateInfo = new SP.ListItemCreationInformation();
    var listItem = extList.addItem(itemCreateInfo);

    //Set the values
    listItem.set_item('Current', data.query.results.quote.LastTradePriceOnly);
    listItem.set_item('Title', 'results');

    listItem.set_item('TradeDate', tradeDate);
    listItem.set_item('TradeDateStamp', tradeDate.getTime());

    listItem.update();
    context.load(listItem);

    context.executeQueryAsync(
        Function.createDelegate(this, addListItemSucceeded),
        Function.createDelegate(this, addListItemFailed)
    );

    function addListItemSucceeded() {
        console.log('Row ' + data.query.count + ' added OK. New ID is ' + listItem.get_id());
    }
    function addListItemFailed(sender, args) {
        console.log('Failed to add row ' + data.query.count + '. ' + args.get_message() + '\n' + args.get_stackTrace());
        console.log(data);
    }
}

Am I doing something wrong? Or is this a bug with SharePoint Online?

Update: The problem occurs when I try to retrieve the value of the Modified date using the Server Object Model:

DateTime lastUpdateDate = DateTime.MinValue;

var web = SPContext.Current.Site.RootWeb;
SPList list = web.Lists[ListName];
SPListItemCollection items = list.GetItems();
foreach (SPListItem i in items)
{
    DateTime modified = (DateTime)i["Modified"];
    if (modified > lastUpdateDate)
    {
        lastUpdateDate = modified;
    }
}

// lastUpdateDate is in the future if a client in a timezone east of Redmond
// updated the data using the client object model
share|improve this question

1 Answer 1

up vote 0 down vote accepted

It might be a Localtime to UTC conversion issue. This normally happens when you have timezone differences from the server. Try converting your Localtime to UTC using the SPTimeZone object and then saving it.

share|improve this answer
    
So, this led me to the answer - there's a good explanation at stum.de/2010/06/10/…. It seems that SP assumes that all DateTime values in a list are specified in either the web's regional timezone, or UTC (depending on how you create your list) - and the server ignores the timezone of your value when you store it, even if your DateTime value is in another time zone. I don't really understand why SP would ignore the timezone when I save a DateTime value (since this information is easily available to it), but that's SP I guess.. –  Dexter Apr 18 '12 at 12:27
    
Dexter, verified results. What makes matters worse is that, if the date column is created and configured as a 'date' column, not jus a 'datetime column', then it is stored as if it has a midnight date. Thus, when it is retrieved through COM, and the clients browser is set to have a timezone "to the left" of the sites timezone, the date column appears to one day off, when there really is only a 1 hour difference. –  1c1cle Mar 25 '13 at 14:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.