Home > OS >  How do I extract the Year from an Excel serial date number
How do I extract the Year from an Excel serial date number

Time:10-01

If I want to convert an Excel serial date to a datetime using PowerShell I can do

$date = 43557

[DateTime]::FromOADate($date)

and the get the entire datetime, but how can I extract only the year from the serial date and pass it to a variable?

CodePudding user response:

Thank you mklement0. Posting your suggestion as an answer to help other community members.

You can use [DateTime]::FromOADate($date).Year.

You can refer to DateTime Struct and Powershell reading Excel date as 5 digit number

  • Related