Jan 04 2020 11:10 AM
Im coding using VBA in excel... Everytime I use a Date variable to store a time value, the output is always in 12 hour clock format. I have used functions to change this but it doesnt work. How do I convert the msgbox output to 24 hour format?
Jan 04 2020 12:28 PM - edited Jan 04 2020 12:29 PM
Hi,
Instead of Date variable, use Variant alone with the Format function as follows:
Sub Test()
Dim MyDate As Variant
MyDate = Format(Time, "hh:mm")
MsgBox MyDate
End Sub
Or without any variables like this:
MsgBox Format(Time, "hh:mm")
If you insist to use Date variable, try this:
Sub Test2()
Dim MyDate As Date
MyDate = Time
MsgBox WorksheetFunction.Text(MyDate, "[hh]:mm:ss")
End Sub
Hope that helps
Jan 04 2020 10:37 PM
Aug 27 2020 06:36 AM
@Haytham Amairah I copied you "Sub Test()" program and run on my Excel 2016, but it still show 12 Hour format.