PowerShell: Date

By Xah Lee. Date: . Last updated: .
# print today's date
Get-Date

Other formats:

Get-Date -Format "yyyy-MM-dd"
# 2021-05-11
Get-Date -Format "yyyyMMdd"
# 20210511
Get-Date -Format "yyyy-MM-ddTHH:mmK"
# 2021-05-11T14:42-07:00
Get-Date -Format "yyyy-MM-dd dddd"
# 2021-05-11 Tuesday
Get-Date -Format "dddd MM/dd/yyyy HH:mm K"
# Tuesday 05/11/2021 14:44 -07:00

Example:

echo ("Start "+ (Get-Date -Format "yyyy-MM-ddTHH:mmK"))

Parse Date

$xDate = [datetime]::ParseExact("2021-12-11 01:00:00", "yyyy-MM-dd hh:mm:ss", [Cultureinfo]::InvariantCulture)

PowerShell

How-to

Advanced

Script Examples