DateTime column imported from CSV is not displayed on SharePoint site.

Copper Contributor

I imported a CSV in PowerShell to create data for a SharePoint list.

 

The date1 in the CSV is "2024-05-02 11:58:28".

 

foreach ($row in $csvData) {
    $parsedDate1 = [datetime]::ParseExact($row.date1, "yyyy-MM-dd HH:mm:ss", [System.Globalization.CultureInfo]::InvariantCulture)
    $parsedDate2 = [datetime]::ParseExact($row.date2, "yyyy-MM-dd HH:mm:ss", [System.Globalization.CultureInfo]::InvariantCulture)

    $jstZone = [System.TimeZoneInfo]::FindSystemTimeZoneById("Tokyo Standard Time")

    $utcDate1 = [System.TimeZoneInfo]::ConvertTimeToUtc($parsedDate1, $jstZone)
    $utcDate2 = [System.TimeZoneInfo]::ConvertTimeToUtc($parsedDate2, $jstZone)

    $formattedDate1 = $utcDate1.ToString("yyyy-MM-ddTHH:mm:ss") + "Z"
    $formattedDate2 = $utcDate2.ToString("yyyy-MM-ddTHH:mm:ss") + "Z"

    Add-PnPListItem -List $ListName -Values @{
        "date1" = $formattedDate1;
        "date2" = $formattedDate2;
    }
}

 

 

However, nothing appears on the SharePoint site, as shown below:

nonoriri_0-1714635207676.png

 

The following script confirms that the data is included.

 

$items = Get-PnPListItem -List $listName

foreach ($item in $items) {
    $date1Value = $item["date1"]
    if ($date1Value -ne $null) {
        Write-Host "Date1: $date1Value"
    } else {
        Write-Host "Date1: No date available"
    }
}

 

 

[Result]
Date1: 05/02/2024 02:58:28

 

* DateTime is also displayed on Galley in Power Apps.

 

How can I get the DateTime to display correctly on the SharePoint site as well,
What format should I specify in Add-PnPListItem?

1 Reply

I don' know why, but I create new SharePoint List from current list.
And DateTime is displayed as I expected.

The old list still does not display the DateTime (looks blank).