Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting VBScript's TimeValue Function

Windows PowerShell

Definition: Returns a Variant of subtype Date containing the time.


OK, so you have a string value (say, 1:45 AM) and you’d like to convert that to a date-time value, is that right? No problem; Windows PowerShell can do that for you. In this command we not only assign the string 1:45 AM to the variable $a, but we also explicitly give $a a datetime data type:

$a = [datetime] "1:45 AM"

When you run this command (assuming it was run on 9/21/2006) and then echo back the value of $a you should get the following:

Thursday, September 21, 2006 1:45:00 AM

Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft