Converting VBScript's Hour Function

Definition: Returns a whole number between 0 and 23, inclusive, representing the hour of the day.


Not that days, months, and years aren't important, mind you, but sometimes all you really need to know is the hour. To return an integer value indicating the hour (based on a 24-hour clock) just use the Get-Date Cmdlet and take a peek at the value of the Hour property:

$a = (get-date).hour

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


Return to the VBScript to Windows PowerShell home page