Help on converting date and time

Hello Community,

Newbie here! i need help on converting date and time in a 12 hr format.
Like 10.15.2022 4:40 PM. is this possible?

Below is my code.
FORMAT_DATETIME_LOCAL(NOW(), “MM.DD.YYYY HH:mm:ss”)

Thanks in Advance.

Echo

Some resources to check before you post:

AppGyver Academy: SAP AppGyver Quick-Start

Troubleshooting FAQ: SAP AppGyver FAQ

Hi,

I don’t think we have some formula already made to convert it, but we can do some math because it’s simple to convert.

How the conversion it’s done:

  1. From 0:00 to 0:59, add 12H to the clock and finish with AM string
  • 0:30 = 12:30 AM
  • 0:55 = 12:55 AM
  1. From 1:00 to 11:59, just add AM string
  • 2:25 = 2:25 AM
  • 9:30 = 9:30 AM
  1. For the remaining, between 13:00 and 23:59, subtract 12H and add PM string
  • 16:55 = 4:55 PM
  • 21:45 = 9:45 PM

You can achive this with some IF statements and formulas like this:

IF(DATETIME_IS_AFTER(SET_TIMEZONE(NOW(), LOCAL_TIMEZONE()), DATETIME(0), "hour") && DATETIME_IS_BEFORE(SET_TIMEZONE(NOW(), LOCAL_TIMEZONE()), DATETIME(1), "hour"), FORMAT_DATETIME_LOCAL(ADD_DURATION(NOW(), 12, "hours"), "MM.DD.YYYY HH:mm") +' AM', IF(DATETIME_IS_AFTER(SET_TIMEZONE(NOW(), LOCAL_TIMEZONE()), DATETIME(1), "hour") && DATETIME_IS_BEFORE(SET_TIMEZONE(NOW(), LOCAL_TIMEZONE()), DATETIME(12), "hour"), FORMAT_DATETIME_LOCAL(NOW(), "MM.DD.YYYY HH:mm") + ' AM', FORMAT_DATETIME_LOCAL(SUBTRACT_DURATION(NOW(), 12, "hours"), "MM.DD.YYYY HH:mm") +' PM'))

Hope this helps

1 Like

Thanks. I will try this.