How to Convert String to Date in PowerShell?

One of my team members recently searched for a solution to convert a string to a date in PowerShell. I suggested different methods. In this tutorial, I will show you how to convert a string to a date in PowerShell with examples.

To convert a string to a date in PowerShell, you can use the [datetime] type accelerator. For example, if you have a date string like "08/19/2024", you can convert it by using [datetime]::ParseExact("08/19/2024", "MM/dd/yyyy", $null). This method ensures the string is interpreted correctly according to the specified format.

Convert String to Date in PowerShell

Now, let me show you how to convert a string to a date in PowerShell using different methods.

Method 1: Using Get-Date

The Get-Date cmdlet is useful in PowerShell and can be used to convert a string to a DateTime object.

Here is an example.

$dateString = "08/09/2025"
$date = Get-Date $dateString
Write-Output $date

In this example, the string “08/09/2025” is converted to a DateTime object using Get-Date.

I executed the above PowerShell script, and you can see the output in the screenshot below:

Convert String to Date in PowerShell

Method 2: Using [datetime]::Parse()

The [datetime]::Parse() method is another way to convert a string to an DateTime object in PowerShell. This method is particularly useful when dealing with different date formats.

Here is an example.

$dateString = "19-Aug-2025"
$date = [datetime]::Parse($dateString)
Write-Output $date

Here, the string “09-Jun-2025” is parsed into a DateTime object.

Here is the output you can see in the screenshot below:

PowerShell Convert String to Date

Check out Convert String to Double in PowerShell

Method 3: Using [datetime]::ParseExact()

Now, let me show you another method to convert string to date in PowerShell using [datetime]::ParseExact(). This method requires you to specify the exact format of the date string.

Here is an example.

$dateString = "2025-06-09"
$format = "yyyy-MM-dd"
$date = [datetime]::ParseExact($dateString, $format, $null)
Write-Output $date

In this example, the string “2025-06-09” is parsed using the format “yyyy-MM-dd”.

Method 4: Using Get-Date with -Format Parameter

The -Format parameter of Get-Date can be used to specify the desired format of the output.

Here is an example of how we can use the Get-Date with -Format parameter to convert string to date in PowerShell.

$dateString = "06/09/2025"
$date = Get-Date $dateString -Format "yyyy-MM-dd"
Write-Output $date

This converts the string “06/09/2025” to a DateTime object and formats it as “yyyy-MM-dd”.

Here is the output in the screenshot below, you can see:

How to Convert String to Date in PowerShell

Check out Convert String to Hashtable in PowerShell

Handle Different Date Formats

In real-world scenarios, you might encounter various date formats. Here are some examples of how to handle them:

Example 1: Convert US Date Format (MM/dd/yyyy)

Here is an example of how to convert a date to a US date format in PowerShell.

$dateString = "06/09/2025"
$format = "MM/dd/yyyy"
$date = [datetime]::ParseExact($dateString, $format, $null)
Write-Output $date

Example 2: Convert European Date Format (dd/MM/yyyy)

Here is an example of how to convert string to European Date Format in PowerShell.

$dateString = "09/06/2025"
$format = "dd/MM/yyyy"
$date = [datetime]::ParseExact($dateString, $format, $null)
Write-Output $date

Read Convert String to JSON in PowerShell

Convert string to date with timezone using PowerShell

Now, let me show you how to convert string to date with timezone using PowerShell. There are different methods to do this.

Using ParseExact Method

You can use the ParseExact method to convert string to date with timezone using PowerShell. Here is an example:

$timeString = '2025-08-19 03:00:00 -0400'
$format = 'yyyy-MM-dd HH:mm:ss zzz'
$culture = [System.Globalization.CultureInfo]::InvariantCulture
$datetime = [datetime]::ParseExact($timeString, $format, $culture)

Handle Time Zones

To handle time zones explicitly, you can use the TimeZoneInfo class:

$timeString = '2025-08-19 03:00:00'
$timeZone = [System.TimeZoneInfo]::FindSystemTimeZoneById('Eastern Standard Time')
$datetime = [datetime]::Parse($timeString)
$datetimeWithTimeZone = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($datetime, $timeZone.Id)

Read How to Convert Base64 String to Text in PowerShell?

Convert String to Date without Time using PowerShell

Now, let me show you how to convert string to date without time using PowerShell.

To convert a string to a date without the time component in PowerShell, you can use the [datetime]::ParseExact method. This method allows you to specify the exact format of the date string and parse it accordingly. Once parsed, you can access the .Date property to get just the date part.

Example

Let’s say you have a date string in the format yyyy-MM-dd , and you want to convert it to a date object without the time component.

Here is the complete PowerShell script.

# Define the date string
$dateString = '2025-08-19'

# Define the format of the date string
$format = 'yyyy-MM-dd'

# Parse the date string to a DateTime object
try {
    $dateTime = [datetime]::ParseExact($dateString, $format, [System.Globalization.CultureInfo]::InvariantCulture)
} catch {
    Write-Error "Failed to parse date string: $_"
    return
}

# Get only the date part
$dateOnly = $dateTime.Date

# Output the result
Write-Output $dateOnly

Explanation

  1. Define the Date String: The variable $dateString holds the date in string format.
  2. Define the Format: The $format variable specifies the format of the date string.
  3. ParseExact Method: The [datetime]::ParseExact method is used to convert the string to a DateTime object. It takes the date string, the format, and a culture info object.
  4. Extract the Date: The .Date property of the DateTime object is accessed to get only the date part, which strips off the time component.

This method ensures that the conversion is accurate and the resulting DateTime object contains only the date without any time information.

You can see the output in the screenshot below after I executed the above PowerShell script.

powershell convert string to date without time

Read Convert String to Int in PowerShell

PowerShell: Convert String to Date yyyymmddhhmmss

To convert a string in the format yyyyMMddHHmmss to a DateTime object in PowerShell, you can use the [datetime]::ParseExact method. This method allows you to specify the exact format of the date and time string and parse it accordingly.

Example

Let’s say you have a date and time string in the format yyyyMMddHHmmss, and you want to convert it to a DateTime object. Here is the complete PowerShell script.

# Define the date and time string
$dateString = '20240819083045'

# Define the format of the date and time string
$format = 'yyyyMMddHHmmss'

# Parse the date and time string to a DateTime object
$dateTime = [datetime]::ParseExact($dateString, $format, [System.Globalization.CultureInfo]::InvariantCulture)

# Output the result
$dateTime

Explanation

  1. Define the Date and Time String: The variable $dateString holds the date and time in string format.
  2. Define the Format: The $format variable specifies the format of the date and time string using yyyyMMddHHmmss.
  3. ParseExact Method: The [datetime]::ParseExact method is used to convert the string to a DateTime object. It takes the date and time string, the format, and a culture info object.
  4. Output the Result: The resulting DateTime object is stored in the $dateTime variable and then outputted.

This method ensures that the conversion is accurate and the resulting DateTime object correctly represents the date and time specified in the string.

You can also see the output in the screenshot below, after I executed the above PowerShell script.

powershell convert string to date yyyymmddhhmmss

Check out How to Convert String to Boolean in PowerShell?

Convert String to Datetime AM/PM using PowerShell

To convert a string that includes an AM/PM designation to a DateTime object in PowerShell, you can use the [datetime]::ParseExact method. This method allows you to specify the exact format of the date and time string and parse it accordingly.

Example

Suppose you have a date and time string in the format MM/dd/yyyy hh:mm tt (where tt denotes the AM/PM designator) and you want to convert it to a DateTime object.

# Define the date and time string
$dateString = '08/19/2024 03:45 PM'

# Define the format of the date and time string
$format = 'MM/dd/yyyy hh:mm tt'

# Parse the date and time string to a DateTime object
$dateTime = [datetime]::ParseExact($dateString, $format, [System.Globalization.CultureInfo]::InvariantCulture)

# Output the result
$dateTime

Explanation

  1. Define the Date and Time String: The variable $dateString holds the date and time in string format, including the AM/PM designator.
  2. Define the Format: The $format variable specifies the format of the date and time string using MM/dd/yyyy hh:mm tt. Here:
    • MM is the two-digit month.
    • dd is the two-digit day.
    • yyyy is the four-digit year.
    • hh is the two-digit hour (12-hour clock).
    • mm is the two-digit minute.
    • tt is the AM/PM designator.
  3. ParseExact Method: The [datetime]::ParseExact method is used to convert the string to a DateTime object. It takes the date and time string, the format, and a culture info object.
  4. Output the Result: The resulting DateTime object is stored in the $dateTime variable and then outputted.

This method ensures that the conversion is accurate and the resulting DateTime object correctly represents the date and time specified in the string, including the AM/PM designator.

Read Convert Strings to Lowercase or Uppercase in PowerShell

PowerShell Convert String to Datetime UTC

To convert a string to a DateTime object in UTC in PowerShell, you can use the [datetime]::ParseExact method along with the ToUniversalTime method. This allows you to specify the format of the date string, parse it, and then convert it to UTC.

Let me show you an example.

Example

Let’s say you have a date and time string in the format yyyy-MM-dd HH:mm:ss and you want to convert it to a DateTime object in UTC.

# Define the date and time string
$dateString = '2024-08-19 15:30:00'

# Define the format of the date and time string
$format = 'yyyy-MM-dd HH:mm:ss'

# Parse the date and time string to a DateTime object
$dateTime = [datetime]::ParseExact($dateString, $format, [System.Globalization.CultureInfo]::InvariantCulture)

# Convert the DateTime object to UTC
$dateTimeUTC = $dateTime.ToUniversalTime()

# Output the result
$dateTimeUTC

Explanation

  1. Define the Date and Time String: The variable $dateString holds the date and time in string format.
  2. Define the Format: The $format variable specifies the format of the date and time string using yyyy-MM-dd HH:mm:ss.
  3. ParseExact Method: The [datetime]::ParseExact method is used to convert the string to a DateTime object. It takes the date and time string, the format, and a culture info object.
  4. Convert to UTC: The .ToUniversalTime() method is called on the DateTime object to convert it to UTC.
  5. Output the Result: The resulting DateTime object in UTC is stored in the $dateTimeUTC variable and then outputted.

This method ensures that the conversion is accurate and the resulting DateTime object correctly represents the date and time in UTC.

Check out Convert Variables to Strings in PowerShell

Convert String to Datetime 24 hour format using PowerShell

To convert a string in a 24-hour time format to a DateTime object in PowerShell, you can use the [datetime]::ParseExact method. This method allows you to specify the exact format of the date and time string and parse it accordingly.

Let me show you an example.

Example

Let’s say you have a date and time string in the format yyyy-MM-dd HH:mm:ss and you want to convert it to a DateTime object.

# Define the date and time string
$dateString = '2024-08-19 14:30:00'

# Define the format of the date and time string
$format = 'yyyy-MM-dd HH:mm:ss'

# Parse the date and time string to a DateTime object
$dateTime = [datetime]::ParseExact($dateString, $format, [System.Globalization.CultureInfo]::InvariantCulture)

# Output the result
$dateTime

Explanation

  1. Define the Date and Time String: The variable $dateString holds the date and time in string format in 24-hour time.
  2. Define the Format: The $format variable specifies the format of the date and time string using yyyy-MM-dd HH:mm:ss.
    • yyyy is the four-digit year.
    • MM is the two-digit month.
    • dd is the two-digit day.
    • HH is the two-digit hour in 24-hour format.
    • mm is the two-digit minute.
    • ss is the two-digit second.
  3. ParseExact Method: The [datetime]::ParseExact method is used to convert the string to a DateTime object. It takes the date and time string, the format, and a culture info object.
  4. Output the Result: The resulting DateTime object is stored in the $dateTime variable and then outputted.

This method ensures that the conversion is accurate and the resulting DateTime object correctly represents the date and time specified in the string in 24-hour format.

Convert String to Date and Add Days in PowerShell

To convert a string to a DateTime object and then add days to it in PowerShell; you can use the [datetime]::ParseExact method to parse the string and the AddDays method to add days to the resulting DateTime object.

Let me show you an example.

Example

Let’s say you have a date string in the format yyyy-MM-dd and you want to convert it to a DateTime object and then add 10 days to it.

# Define the date string
$dateString = '2024-08-19'

# Define the format of the date string
$format = 'yyyy-MM-dd'

# Parse the date string to a DateTime object
$dateTime = [datetime]::ParseExact($dateString, $format, [System.Globalization.CultureInfo]::InvariantCulture)

# Add 10 days to the DateTime object
$newDateTime = $dateTime.AddDays(10)

# Output the result
$newDateTime

Explanation

  1. Define the Date String: The variable $dateString holds the date in string format.
  2. Define the Format: The $format variable specifies the format of the date string using yyyy-MM-dd.
  3. ParseExact Method: The [datetime]::ParseExact method is used to convert the string to a DateTime object. It takes the date string, the format, and a culture info object.
  4. Add Days: The .AddDays(10) method is called on the DateTime object to add 10 days to it.
  5. Output the Result: The resulting DateTime object, with 10 days added, is stored in the $newDateTime variable and then outputted.

This method ensures that the conversion is accurate and the resulting DateTime object correctly represents the date with the specified number of days added.

Conclusion

In this tutorial, I have explained how to convert string to date in PowerShell using different methods. You can use various methods like:

  • Use Get-Date for simple conversions.
  • Use [datetime]::Parse() for more flexibility.
  • Use [datetime]::ParseExact() for precise control over date formats.
  • Use Get-Date with the -Format parameter for specific output formats.

I have also explained the below examples:

  • Convert string to date with timezone using PowerShell
  • Convert String to Date without Time using PowerShell
  • PowerShell: Convert String to Date yyyymmddhhmmss
  • Convert String to Datetime AM/PM using PowerShell
  • PowerShell Convert String to Datetime UTC
  • Convert String to Datetime 24-hour format using PowerShell
  • Convert String to Date and Add Days in PowerShell

I hope this helps you. Do let me know in the comments below if you have any questions.

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.