Converting VBScript's DateValue Function

Windows PowerShell

Definition: Returns a Variant of subtype Date.


How can you make sure Windows PowerShell treats a value as a date and not as, say, a string? One way is to explicitly “cast” that value as a date-time value. For example, this command assigns the string 12/1/2006 to the variable $a, at the same time making $a a date-time value:

$a = [datetime] "12/1/2006"

When you run this command and then use the GetType() method to retrieve the data type for $a you should get the following:

IsPublic IsSerial Name
-------- -------- ----
True     True     DateTime

Return to the VBScript to Windows PowerShell home page