viewpoint-particle

Author Topic: 24h to 12h time.  (Read 471 times)

morenos1

  • Jr. Member
  • **
  • Posts: 65
24h to 12h time.
« 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 ....

td

  • Tech Support
  • *****
  • Posts: 2538
    • WinBatch
Re: 24h to 12h time.
« Reply #1 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


Code: Winbatch
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
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates