Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > FusionPro® VDP Creator


Thread Tools Search this Thread Display Modes
Old May 20th, 2022, 07:00 AM
draco_66 draco_66 is offline
Forum n00b
Join Date: May 2022
Location: NY
Posts: 2
Default Complex Time Formatting Rule

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.

Last edited by draco_66; May 20th, 2022 at 07:04 AM..
Reply With Quote
Old May 20th, 2022, 03:01 PM
ThomasLewis's Avatar
ThomasLewis ThomasLewis is offline
Senior Contributor
Join Date: Feb 2011
Posts: 236
Default Re: Complex Time Formatting Rule

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;
	return dd1_full + " - " + dd2_full;
Reply With Quote
Old May 23rd, 2022, 01:49 PM
draco_66 draco_66 is offline
Forum n00b
Join Date: May 2022
Location: NY
Posts: 2
Thumbs up Re: Complex Time Formatting Rule

Thank you very much for this. This should do exactly what I need.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 05:03 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.