Sven Posted April 8, 2011 Share Posted April 8, 2011 After a marathon of coding I've reached the point where I can't think straight anymore. All i'm trying to do is to convert any hour from the AM / PM system to the 24hour system, and am wondering if I got the function below right or not. $test = _convert_hour(12, "am") msgbox(0, "test", $test) Func _convert_hour($hour, $am_pm) $am_pm = StringLower($am_pm) If $am_pm = "am" And $hour = 12 Then return ($hour - 12) If $am_pm = "pm" And $hour >= 1 And $hour <= 11 Then return ($hour + 12) return ($hour) EndFunc ;==>_convert_hour Thank you for your feedback. Link to comment Share on other sites More sharing options...
metis Posted April 8, 2011 Share Posted April 8, 2011 (edited) MsgBox(0,"", _TimeHrMin()) ; 24 to am/pm format MsgBox(0,"", _TimeHrMin2()) ; am/pm format to 24 MsgBox(0,'', @HOUR & ":"& @MIN & ":"& @SEC & "...Format 24") ; 24 to 24 format Func _TimeHrMin() $hr = @HOUR If $hr > 12 Then $hr = $hr -12 $x = "PM" Else $x = "AM" EndIf $time = $hr & ":" & @MIN & " " & $x Return Func _TimeHrMin2() $hr = @HOUR If $hr < 12 Then $x = "PM/AM" EndIf $time = $hr & ":" & @MIN & " " & $x Return ($time) EndFunc ($time) EndFunc Edited April 8, 2011 by metis Link to comment Share on other sites More sharing options...
UEZ Posted April 8, 2011 Share Posted April 8, 2011 Here another method: Func Convert24h($time, $format) ;am/pm to 24h format by UEZ If $format = "am" Then Return Mod($time, 12) Return Mod($time + 12, 24) EndFunc Br, UEZ argumentum 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Sven Posted April 8, 2011 Author Share Posted April 8, 2011 Thanks, greatly appreciated. UEZs method is very elegant. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now