Hi, I'm struggling to implement a custom date time format regular expression for the following format: MM/DD/YYYY, hh:mm A Example: 1/24/2023 11:30 AM I tried something this, but not sure how to implement it in a regex action: \d{2}/\d{2}/\d{4}\s+\d{2}:\d{2}\s+(AM|PM)
I also tried to do it on a task form, however could not do it on a submit rule (its used for a comment log, so it has to be on the submit rule).
Also tried the format date action, but it returns the seconds as well as a day behind from the current date time for some odd reason
Page 1 / 1
Hi @Prineel_V3
This is doable…
Step 01: Format date to String.
Format: YYYY-MM-DD HHss Output: txt_CurrentDate
Step 02: Apply Regex to extract Date
Input: txt_CurrentDate (Output from Step 1)
Replace
Pattern: (\d{4})-(\d{2})-(\d{2})(.*)
Replacement: $2/$3/$1
Output: txt_FormatDate
Step 03: Apply Regex to extract Time
Input: txt_CurrentDate (Output from Step 1)
Replace
Pattern: (\d{4})-(\d{2})-(\d{2})(.*)
Replacement: $4
Output: txt_FormatTime
Step 04: Apply Regex to extract Hour
Input: txt_FormatTime (Output from Step 3)
Replace
Pattern: (\d{2}):(\d{2}):(\d{2})
Replacement: $1
Output: txt_Hours
Step 05: Convert txt Hours into Integer
Input: txt_Hours (Output from Step 4)
Output: int_Hours
Step 06
Check if Hours equals 00
Check if Hours equal 12
Check if Hours less than 12
BRANCH If int_Hours == 0
Step 06a: Apply Regex
Input: txt_FormatTime (Output from Step 3)
Replace
Pattern: (\d{2}):(\d{2}):(\d{2})
Replacement: 12:$2 AM
Output: txt_FormatTime
Explanation: If the time is 00:00:01 or 00:30:20, we are going to format it as 12:00 AM or 12:30 AM
BRANCH If int_Hours == 12
Step 06b: Apply Regex
Input: txt_FormatTime (Output from Step 3)
Replace
Pattern: (\d{2}):(\d{2}):(\d{2})
Replacement: 12:$2 PM
Output: txt_FormatTime
Explanation: If the time is 12:00:01 or 12:30:20, we are going to format it as 12:00 PM or 12:30 PM
BRANCH If int_Hours < 12
Step 06c: Apply Regex
Input: txt_FormatTime (Output from Step 3)
Replace
Pattern: (\d{2}):(\d{2}):(\d{2})
Replacement: int_hour:$2 AM
Output: txt_FormatTime
Explanation: Get hours and minutes, append AM
BRANCH If int_Hours < 12 (The NO branch)
Additional Step → Minus 12 from int_Hours
Step 06d: Apply Regex
Input: txt_FormatTime (Output from Step 3)
Replace
Pattern: (\d{2}):(\d{2}):(\d{2})
Replacement: int_hour:$2 PM
Output: txt_FormatTime
Explanation: Get hours and minutes, append PM
TESTING RESULT
I used a Datetime control for input instead of getting the actual Datetime from Context
Hope that helps
Hi,
My reaction:
I think I will just use one of the built in formats in the convert a value action to avoid too many steps (unless it has to be in that specific format). Thanks for this solution though :)
If you haven’t voted for it already, there’s an idea out there to add more options to the Format Date to String action.