Was this page helpful?
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 TimeSerial Function

Windows PowerShell

Definition: Returns a Variant of subtype Date containing the time for a specific hour, minute, and second.


Like DateSerial, this is a function that is in no danger of being overused. However, if you want to pass in values for the hours, minutes, and seconds and get back a time value (as opposed to a date-time value) the following command will do the trick:

$a = get-date -h 17 -mi 10 -s 45 -displayhint time

Note. As you probably figured out for yourself, the -h parameter represents the hours, the -mi parameter represents the minutes, and the -s parameter represents the seconds. Values for the hours are based on a 24-hour clock.

When you run this command and then echo back the value of $a you should get the following:

5:10:45 PM

Return to the VBScript to Windows PowerShell home page

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