0

i noticed while testing that the sharepoint get list item call i am making through pnp sp is wrong. i tried going to the endpoint url directly to check but the return date is the same (wrong date) .

_api/web/lists/getByTitle(title)/items?

sharepoint list item:

datefield1 saved in sp list: 11/14/2018 1:30 PM returning as: 2018-11-14T21:30:00Z

datefield2 saved in sp list: 11/12/2018 8:47 PM returning as: 2018-11-13T04:47:00Z

my code to retrieve is pretty straightforward;

 public checkLockStatus(currentUser: any, division: string, qnaListTrackingListName: string): Promise<any>{
        return sp.web.lists.getByTitle(listname).items.select(
        "LastUpdated","LastPublished", "LockedBy/Id", "LockedBy/EMail", 
        "LockedReleaseTime")
            .expand("LockedBy")
            .get()
            .then((items: any[]) => {
                if(items.length == 0) {
                    console.log(items, "item does not exist. creating now");
                   //some code 
                } else {
                    console.log(items, "item exists. returning");
                    return items;
                }            
        }).catch((error) => {
            console.log(error);
            return error;
        });
    }
0

It's a common issue when retrieving the date object in SharePoint because REST do not bring back the client side time, it brings back the server time.

This happens because in SharePoint UI, when you're setting the date field without time, it will assume that you're setting dd-MM-yyyy 00:00:00 of your local time. But in database it will try to adjust the date to server site time. And that's what you're getting from REST service.

If your site LocaleId in the browser is same as it was on the server during saving the date, then it should return right value.

If not, then you will have to manually adjust the timezone. Regional settings may be something that can help you. In SP 2013 you can also access it from the REST Api:

Source:

REST endpoints for Regional settings.

  • 1
    yeah ive checked the regional settings, can;t believe i missed this part. – Page F.P.T Nov 14 '18 at 8:59
0

You need to convert the values to local time. (:00Z = Zulu time)

let date_formatted1 = datefield1.toLocaleDateString();
console.log(date_formatted1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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