draco_66 Posted May 20, 2022 Share Posted May 20, 2022 (edited) Looking for some help on formatting time. If this is even possible. There will be several Time fields on the item so I would also like to know if I will need this rule for each field or can it be called somehow for multiple fields. There will be two drop downs to pick a start and end time. The final output needs to be formatted in a particular way. Here are examples of the possible inputs from the drop downs and how the final time needs to be formatted. Drop Down 1-------Drop Down 2----------Final Output Should Be 10:00 a.m.-------------11:00 a.m.-------------10 – 11 a.m. 11:15 a.m.-------------Noon-------------------11:15 a.m. – Noon 11:30 a.m.-------------12:30 p.m.-------------11:30 a.m. – 12:30 p.m. 2:00 p.m.---------------3:15 p.m.--------------2 – 3:15 p.m. 8:00 a.m.---------------------------------------8 a.m. 2:15 p.m.---------------------------------------2:15 p.m. Any help would be appreciated. Thank you. Edited May 20, 2022 by draco_66 Quote Link to comment Share on other sites More sharing options...
ThomasLewis Posted May 20, 2022 Share Posted May 20, 2022 This should work for you. Just a precaution though, you need to make sure you put that space in between the time and the meridiems. This works by splitting the time up into 3 sections, the hour, the minutes, and the meridiems. This first check is to see if one of the 2 drop downs is not used and just outputs what is there. The second checks if the meridiems match, if so it just uses the hour of the first drop down Lastly, if both drop downs are used and the meridiems dont match, it outputs the values as is with a hyphen between them. I have no doubt there is a more succinct way to achieve this, but this should work for what it is. var dd1_full = Field("Drop Down 1"); var dd2_full = Field("Drop Down 2"); var dd1_split = dd1_full.split(/[\:\s]/); var dd2_split = dd2_full.split(/[\:\s]/); if (!dd1_full || !dd2_full) return dd1_full + dd2_full; else if (dd1_split[2] == dd2_split[2]) return dd1_split[0] + " - " + dd2_full; else return dd1_full + " - " + dd2_full; Quote Link to comment Share on other sites More sharing options...
draco_66 Posted May 23, 2022 Author Share Posted May 23, 2022 Thank you very much for this. This should do exactly what I need. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.