Author : HASSAN MD TAREQ | Updated : 2021/09/25

Get DateTime

$dateTime = (Get-Date)
echo $dateTime

# Get-Date 'xxx xxx xxx' -Format 'yyyymmdd

Format DateTime

$targetDateTime = (Get-Date) # assign the date you want i.e. (Get-Date 'xxx xxx xxx' -Format 'yyyymmdd')
$dateTimeFormatSpecifier = "yyyyMMddHHmmss"

#$fromattedDateTimeString = (Get-Date $targetDateTime -Format $dateTimeFormatSpecifier)
$fromattedDateTimeString = $targetDateTime.ToString($dateTimeFormatSpecifier)
echo $fromattedDateTimeString