Powershell date format yyyymmddhhmmss

In PowerShell, you can use the Get-Date cmdlet and string formatting to achieve the desired date format (YYYYMMDDHHMMSS). Here’s an example:

# Get the current date and time
$currentDateTime = Get-Date

# Format the date and time in YYYYMMDDHHMMSS format
$formattedDateTime = $currentDateTime.ToString("yyyyMMddHHmmss")

Write-Host $formattedDateTime

Running this PowerShell script will output the current date and time in the format “YYYYMMDDHHMMSS”

In this example, $currentDateTime is assigned the current date and time using Get-Date. Then, the ToString method is called on the $currentDateTime object with the format string “yyyyMMddHHmmss” to get the desired format. The result is stored in the variable $formattedDateTime, which can be used or printed.


The Get-Date cmdlet in PowerShell supports various date and time formatting options using custom format strings. Here are some standard format specifiers that you can use with the ToString() method when formatting dates and times:

d: Short date pattern (e.g., "8/10/2023").
D: Long date pattern (e.g., "Wednesday, August 10, 2023").
f: Full date and short time pattern (e.g., "Wednesday, August 10, 2023 12:34 PM").
F: Full date and long time pattern (e.g., "Wednesday, August 10, 2023 12:34:56 PM").
g: General date and short time pattern (e.g., "8/10/2023 12:34 PM").
G: General date and long time pattern (e.g., "8/10/2023 12:34:56 PM").
M or m: Month and day pattern (e.g., "August 10").
O or o: Round-trip date/time pattern (ISO 8601 format).
R or r: RFC1123 pattern (e.g., "Wed, 10 Aug 2023 12:34:56 GMT").
s: Sortable date/time pattern (e.g., "2023-08-10T12:34:56").
t: Short time pattern (e.g., "12:34 PM").
T: Long time pattern (e.g., "12:34:56 PM").
u: Universal sortable date/time pattern (e.g., "2023-08-10 12:34:56Z").
U: Full date and time with universal sortable pattern (e.g., "Wednesday, August 10, 2023 4:34:56 PM").
Y or y: Year and month pattern (e.g., "August 2023").

You can use these format specifiers with the ToString() method to format the date and time according to your needs. For example:

$currentDateTime = Get-Date
$formattedDateTime = $currentDateTime.ToString("yyyyMMddHHmmss")
Write-Host $formattedDateTime