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

Get DateTime

$dateTime = (Get-Date)
echo $dateTime

echo $dateTime -DisplayHint Time

echo $dateTime -Format 'yyyymmdd'
# 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