Sign in to follow this  
Followers 0
youknowwho4eva

12 Hour Clock

5 posts in this topic

How do you make the hour return in 12 hour format instead of 24 hour format? I would search 12 Hour format but search doesn't allow words of less then 3 characters ;) .


Giggity

Share this post


Link to post
Share on other sites

If you are talking about the @hour macro just subtract 12.

$hour = @HOUR
$string = "AM"
If $hour > 12 Then
    $hour -= 12
    $string = "PM"
EndIf
MsgBox(0,"", $hour & " " & $string)

Share this post


Link to post
Share on other sites

If you are talking about the @hour macro just subtract 12.

$hour = @HOUR
$string = "AM"
If $hour > 12 Then
    $hour -= 12
    $string = "PM"
EndIf
MsgBox(0,"", $hour & " " & $string)
It's almost, but not quite that simple. In your script, 00 hours in the morning would stay 00, not 12 AM. Also 12 noon would stay AM vice PM. Try:
Global $iHour = @HOUR, $sAMPM = "AM"
If $iHour >= 12 Then $sAMPM = "PM"
If $iHour = 00 Then $iHour = 12
If $iHour > 12 Then $iHour -= 12

MsgBox(64, "12H Time", "It's " & $iHour & ":" & @MIN & " " & $sAMPM)

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

;) How did I not think of that? Thank you much sir. I guess I was looking to hard to find a one liner instead of thinking to subtract 12. :D Isn't midnight displayed as 00? (the range says 00 to 23)No one should be on my program at midnight, but just to be accurate I'd have to add the extra if $hour = 0 then $hour += 12.

Edit: Psatlyds beat me to it

Edited by youknowwho4eva

Giggity

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0