WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: morenos1 on February 08, 2018, 01:52:57 PM

Title: 24h to 12h time.
Post by: morenos1 on February 08, 2018, 01:52:57 PM
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 ....
Title: Re: 24h to 12h time.
Post by: td on February 08, 2018, 02:05:47 PM
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 (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