Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Convert to A.M. / P.M. format in a script ?

Featured Replies

I have a script that generates a time based on a calculation. Could someone tell me how to have the script convert it to the format A.M./P.M. instead of the 24 hour format that it is ending up in.

(currently it's resulting in 14:30:00 instead of 2:30 P.M. which is what I would prefer)

Edited by Guest

That's how FM stores time. You'll need to change how the time is displayed by clicking on the Time Format options on the context menu (or whatever its called on a Mac).

Steve

  • Author

I'm not concerned with how the date looks on the layout. I know I can change the format of the field on the layout. B)-) The thing is, I want to use that field in an email that goes out, and I want the time of the pulled value to be in AM/PM format, not in 24 hour time.

Perhaps if I write a function that finds the hour of the time and if it's over 12 , give back hour-12 , concatenate it with minutes, and if it's over 12 , stick a PM onto it... hmmm... maybe I can do this.. seems pretty complicated... I thought there was an easier way... but maybe not.. I guess I'll at least try this.

If anyone has any input, I'd love to hear it!! :)-)

  • Author

Yipeeee B)-) I think I did it !! :)-)

---------

Case (

Minute(time) > 10;

Case(

Hour ( time ) = 24;

(Hour (time)-12) &":"& Minute(time) & " AM";

Hour ( time ) = 12;

(Hour (time)) &":"& Minute(time) & " PM";

Hour ( time ) > 12;

(Hour (time) - 12) &":"& Minute(time) & " PM";

Hour ( time ) = 0;

(Hour (time) + 12 ) &":"& Minute(time) & " AM";

Hour ( time ) < 12;

(Hour (time) ) &":"& Minute(time) & " AM");

Minute(time) < 10;

Case(

Hour ( time ) = 24;

(Hour (time)-12) &":0"& Minute(time) & " AM";

Hour ( time ) = 12;

(Hour (time)) &":0"& Minute(time) & " PM";

Hour ( time ) > 12;

(Hour (time) - 12) &":0"& Minute(time) & " PM";

Hour ( time ) = 0;

(Hour (time) + 12 ) &":0"& Minute(time) & " AM";

Hour ( time ) < 12;

(Hour (time) ) &":0"& Minute(time) & " AM") )

-------

See here.

  • Author

Um...

Any chance someone can explain what this funky calculation is doing !? B)-)

(and also,.... how it is doing it ?)

--

Hour ( theTime ) - 12 * ( theTime >= 13*3600 ) & ":" &

Right ( "00" & Minute ( theTime ) ; 2 ) &

Choose ( theTime >= 12*3600 ; " AM" ; " PM" )

If theTime is greater than or equal to 46800 (the numerical equivalent of 13:00:00 or 1 PM), then the test in parentheses returns a 1 and 12 is subtracted from the hour. A leading zero is then added to the minute if it is less than 10. (Note that Right( "0" & Minute(theTime); 2 ) would work also). Then, PM is added if theTime is greater than or equal to 43200 (12 PM); otherwise AM is added.

Does that help?

Well the point is that one day is 86400 seconds. But since 12 AM is noon, will the switch be after 12:59 which is 13*3600 seconds since the beginning of the day. The stuff in just after 12* is either 0 or 1, while Hour( gives the time in 24 hours.

Next part needs to take care of what is called leading zeros, for the first 9 minutes of each hour.

The larst part carries some of the logic of the first third, it could have been a Case( or If( instead, but Choose( is believed to be a tad faster than Case( or If(

--sd

Ha Ha ...since when have we become siamese twins???

--sd

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.