24h to 12h time.

Started by morenos1, February 08, 2018, 01:52:57 PM

Previous topic - Next topic

morenos1

Taking the hour from: now=TimeYmdHms()

xhour= ItemExtract(4,now,":")
xmin=  ItemExtract(5,now,":")

I need to convert the time from 24h format to 12h format.

Any help will be much appreciated ....

td

The simplest way is to use the TimeFormat function.  More information on the function can be found in the Consolidated WIL Help file.  If your version is too old to have that function then it is a matter of a little arithmetic:

From the Tech Database article http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/UDF~-~UDS~Library/Time~UDFs+Format~Current~Date~and~Time.txt


Code (winbatch) Select
if Hour24 < 12
      Hour12 = Hour24                      ; Get 12-hour format hour
      AMPM   = "am"                        ; and AM/PM value
else
      Hour12 = Hour24 - 12
      AMPM   = "pm"
endif
if Hour12 == 0 then Hour12 = 12

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade