This project has moved and is read-only. For the latest updates, please go here.

Current Server date time

Oct 3, 2011 at 1:33 PM



Is there possible using SPService to get current datetime on the SharePoint server?

I'm using SPServices Query to display the list of the last entries from one of the Search Scopes and I want to implement displaying how many time pass from the entry was added, e.g. "News Title - added 8 hours ago"




Oct 4, 2011 at 4:05 PM

It sounds like you need the current date/time (which you can get on the client) and the Created date/time (which is part of the item).

I'm not aware of a way to get the server date/time, but it may be possible.


Jan 12, 2015 at 11:23 PM
I'm running into a similar problem today. I'm reading datetime values from datetime fields in SharePoint records with SP Services (and getting the same values as if view the record in the standard SharePoint UI) and comparing them to the current time. The value I get is dependent on my SharePoint Timezone settings (e.g. in SP 2010 if the user pulls down the menu where their name is displayed in the upper right-hand corner then chooses "My Settings" then chooses "My Regional Settings").

I'm on Pacific Time (UTC-8); the server I'm working with is on Eastern Time (UTC-5). If I have Eastern Time selected in my SharePoint regional settings, then I might get a "Created" datetime of 5:16 pm...but when I change to Pacific Time, the same "Created" value returns as 2:16 pm. Who knows what settings any of our users have across the country. And of course in my JavaScript I'll the current date based on the user's computer's regional settings.

The Created date any user sees (either through the SharePoint UI or SPService query) will be different depending on the user's SharePoint regional settings, but I don't know what those settings are. So if I wasn to calculate and display how much time has elapsed between my "Created" time and right-this-very-minute, how do I do it?

Is there some way to have SPServices return datetime values in a specific time zone (GMT, e.g.?) Is there some way I can get the current server time in the same SharePoint regional setting that the user is seeing for everything else?
Jan 13, 2015 at 1:07 AM
Have discoverd that setting the CAMLQueryOptions "DateInUtc" parameter causes all the datetimes to return in UTC:
 CAMLQueryOptions: "<QueryOptions<DateInUtc>True</DateInUtc></QueryOptions>",
I think this is going to do the trick.