1

My SharePoint list contains 4 columns and the first is a date column. The data in the list is sorted ascending. What I would like is to get the value of the first column af the last row of the list. I have this but doesn't give me the last date:

Write-Host "my schedule: " (Get-PnPListItem -List "my schedule" | Select-Object -Last 1)["Datum"].ToString("dd.MM.yyyy")

When I go to the end of my list "My schedule" I see the last date is 31-03-2019 but powershell gives me 30-03-2019 !!!

What do I do wrong?

2

You say the data is sorted ascending, but I'm guessing that it's the view that's sorted. get-pnplistitem isn't retrieving items based on a view, but based on the raw data. But if you check the docs, example #5 has a sample for using a caml query, which would allow you to both sort the data as well as to set a rowlimit. (the example only provides a where statement, but here is an example of sorting with a caml query, and here is an example of rowlimit.

  • I think the time is stored as a date/time object, and I have read that it could have one of the 3 properties: UTC, Local, or Unspecified – Peter Kiers Jan 10 at 20:18
  • I think determine what kind of property is set to the date/time object and declare it in my code. I think that will solve my problem. But I have no idea how to do that. I think the values can be found in the "kind" property – Peter Kiers Jan 10 at 20:20
  • I have tried: ....["Datum"].ToLocalTime.ToString("dd.MM.yyyy") – Peter Kiers Jan 10 at 20:25
  • Buit get an error: can not find an overload for "tostring and the argument count: "1" – Peter Kiers Jan 10 at 20:26
  • Sorry, misunderstood the question. But check your syntax, as you're missing () after the call to ToLocalTime: ToLocalTime().ToString("dd.MM.yyyy") – Mike2500 Jan 10 at 20:38

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.