ConvertTo Date - PPOSHGROUP/PPoShTools GitHub Wiki

ConvertTo-Date

PPoShTools -> ConvertTo-Date.ps1

Synopsis

Converts a string to a DateTime using specified DateFormat.

Syntax

ConvertTo-Date [[-String] <String>] [[-DateFormat] <String[]>] 
[-ThrowOnFailure] [<CommonParameters>]

Description

See https://msdn.microsoft.com/en-us/library/az4se3k1%28v=vs.110%29.aspx for description of format strings.

Parameters

-String<String>

String to be converted to date.

  • PipelineInput: false
  • Required: false

-DateFormat<String[]>

Date formats that will be used to parse the string. If not specified, system default will be used.

  • PipelineInput: false
  • Required: false

-ThrowOnFailure<SwitchParameter> (default: False)

If true, exception will be thrown if failed to convert string to date. Otherwise, $null will be returned.

  • DefaultValue: False
  • PipelineInput: false
  • Required: false

Examples

Example 1

$date = ConvertTo-Date -String '2015-03-05' -DateFormat 'yyyy-MM-dd'
⚠️ **GitHub.com Fallback** ⚠️