Converting VBScript's CDate Function
Definition: Returns an expression that has been converted to a Variant of subtype Date.
CDate
Need to make sure that a value is treated as a date? Then do this. First, assign the value to a variable; here we’re assigning the string 11/1/2006 to the variable $a:
$a = "11/1/2006"
In fact, if we now call the GetType() method we’ll see that $a is a string variable:
IsPublic IsSerial Name
-------- -------- ----
True True String
To convert $a to a date-time value we can use this command:
$a = [datetime] $a
When you run this command and check the data type for $a you should get the following:
IsPublic IsSerial Name
-------- -------- ----
True True DateTime