Reputation: 238
I have a SharePoint online site with UTC+2 timezone. and i need to understand when i get data from SharePoint using PnP Core SDK version 1.11.0 how the TimeZone for any Datetime SharePoint columns will be shown in?
Here is my case:-
1)My SharePoint Online site time zone is UTC+2
2)I have a .net core console application which uses PnP Core SDK version 1.11.0
3)The hosting server which have visual studio 2022 has UTC+2 time zone also.
4)I am getting all the items from a SharePoint list suing this code:-
var BCDList = context.Web.Lists.GetByTitle("BookingCalendarDetails", p => p.Title,
p => p.Fields.QueryProperties(p => p.InternalName,
p => p.FieldTypeKind,
p => p.TypeAsString,
p => p.Title));
// Build a query that only returns these fields for the Work Orders
string viewXml10_20 = @"<View Scope='RecursiveAll'>
<ViewFields>
<FieldRef Name='Title' />
<FieldRef Name='ContractType' />
<FieldRef Name='Created' />
<FieldRef Name='FileLeafRef' />
<FieldRef Name='Amount' />
<FieldRef Name='BookingCalendarID' />
<FieldRef Name='NetworkID' />
<FieldRef Name='StartDate1' />
<FieldRef Name='EndDate1' />
<FieldRef Name='MediumID' />
<FieldRef Name='MediumTitleSync' />
</ViewFields>
<Query>
<Where>
<And>
<And>
<Eq>
<FieldRef Name='FSObjType' />
<Value Type='Integer'>0</Value>
</Eq>
<Eq>
<FieldRef Name='IsCanceled' />
<Value Type='Boolean'>0</Value>
</Eq>
</And>
<Eq>
<FieldRef Name='ContractType' />
<Value Type='Choice'>Out of Home</Value>
</Eq>
</And>
</Where>
</Query>
<RowLimit Paged='TRUE'>5000</RowLimit>
</View>";
// Load all the needed data using paged requests
bool paging10_20 = true;
string nextPage10_20 = null;
while (paging10_20)
{
var output = await BCDList.LoadListDataAsStreamAsync(new RenderListDataOptions()
{
ViewXml = viewXml10_20,
RenderOptions = RenderListDataOptionsFlags.ListData,
Paging = nextPage10_20 ?? null,
}).ConfigureAwait(false);
if (output.ContainsKey("NextHref"))
{
nextPage10_20 = output["NextHref"].ToString().Substring(1);
}
else
{
paging10_20 = false;
}
}
Now for a list item with ID = 1838, I have added the StartDate1 as 1/10/2024 + the EndDate1 as 1/11/2024, and they will be shown inside SharePoint UI correctly as follow:-
And when i use the SharePoint REST API to get this item using this url https://******.sharepoint.com/sites/PPM/_api/web/lists/getbytitle('bookingcalendardetails')/items(1838)
,,,,the StartDate1 & EndDate1 will be stored in UTC as follow:-:-
<d:StartDate1 m:type="Edm.DateTime">2024-09-30T21:00:00Z</d:StartDate1>
<d:EndDate1 m:type="Edm.DateTime">2024-10-31T22:00:00Z</d:EndDate1>
now when i run the console application using Visual Studio , the StartDate1 & EndDate1 will be shown based on the site time zone, as follow:-
So how did PnP Core SDK did the conversion correctly? i thought that Visual Studio will show the Dates in UTC time zone , since this is how SharePoint online stores the dates.. so i am not sure how my code get the dates in the correct time zone which is the site time zone? is it the visual studio how did the conversion? or this conversion will be done by the PnP Core SDK based on the sharepoint site time zone? or this conversion will be done by the PnP Core SDK based on the hosting server (where the .net console application runs at)?
Upvotes: 0
Views: 125