Skip to main content
Nintex Community Menu Bar
Solved

Custome DateTime Format


Forum|alt.badge.img+8

Hi, 

 

Is there a way to use a custom date format in NWC (Im looking for an action that can do this). 
My date time format should be something like this: MM/DD/YYYY HH:MM:SS so it will display something like this: 02/04/2023 13:25:53 

I tried using the NWC Tools Format DateTime Action, but it just gives an error saying “The specified DateTime value has an unsupported DateTime pattern. [Error Code: TypeCasting.UnsupportedDateTimePattern]”. I also used convert a date to string, but there's no option for a custom format. Any suggestions?

Best answer by Garrett

Hi @Prineel_V3 

Regex only works on text strings not datetime objects.

 

Here is the solution

Step 1: Using “Format Date to String”. Ensure the format has all the correct values (Year is YYYY, Month is MM). Month must be in correct value. MM = 01, MMM = Jan, MMMM = January. 

Step 2: Apply a regular expression on the output from Step 1.

Regex pattern is 

(\d{4})-(\d{2})-(\d{2})(.*)

Replacement text is

$2/$3/$1$4

Step 3: Output to Log to History

Output from the Log to History

 

Hope that helps

 

View original
Translate
Did this topic help you find an answer to your question?

8 replies

Garrett
Forum|alt.badge.img+16
  • Scout
  • 904 replies
  • January 5, 2023

Hi @Prineel_V3 

First, use the “Format Date to String”. Store value into variable.

Next, apply Regex (Regular Expression) on that string to format into your required formatting  

Translate

Forum|alt.badge.img+8
  • Author
  • Nintex Employee
  • 82 replies
  • January 5, 2023

Hi @Garrett ,

 

I did also attempt this, but there are no valid/usable operations to convert a datetime variable to a custom format (I could be doing something wrong though)

Translate

Garrett
Forum|alt.badge.img+16
  • Scout
  • 904 replies
  • Answer
  • January 5, 2023

Hi @Prineel_V3 

Regex only works on text strings not datetime objects.

 

Here is the solution

Step 1: Using “Format Date to String”. Ensure the format has all the correct values (Year is YYYY, Month is MM). Month must be in correct value. MM = 01, MMM = Jan, MMMM = January. 

Step 2: Apply a regular expression on the output from Step 1.

Regex pattern is 

(\d{4})-(\d{2})-(\d{2})(.*)

Replacement text is

$2/$3/$1$4

Step 3: Output to Log to History

Output from the Log to History

 

Hope that helps

 

Translate

Forum|alt.badge.img+10
  • Scout
  • 129 replies
  • January 5, 2023

Sounds like a good enhancement request to me!  I can’t think of a good reason why the “Format date to string” action shouldn’t be able to take a custom format - just like the formatDate function in a form. 

 

As a side note, I did try to use an autocompleting form to convert a datetime variable to a custom format, but it looks like autocompleted forms don’t evaluate any variables within them.

Translate

Forum|alt.badge.img+8
  • Author
  • Nintex Employee
  • 82 replies
  • January 5, 2023

Thanks @Garrett 

Translate

Forum|alt.badge.img+1
  • Rookie
  • 2 replies
  • May 22, 2023

@Garrett  Thank you for providing the regex solution above. Can you help me to convert format “dddd, dd MMM YYYY” to US format “dddd, MMM dd YYYY” please? I cannot figure out the pattern and replacement text if I want “Monday, 22 May 2023” to display as “Monday, May 22, 2023”. 

Translate

Garrett
Forum|alt.badge.img+16
  • Scout
  • 904 replies
  • May 22, 2023

Hi @jleung 

Here you go

Pattern:
(\w+,) (\d{2}) (\w+) (\d{4})

Replacement Text:
$1 $3 $2, $4

 

Testing

Date     : Sunday, 01 Jan 2023
Formatted: Sunday, Jan 01, 2023

Date     : Wednesday, 18 Jan 2023
Formatted: Wednesday, Jan 18, 2023

Date     : Friday, 28 Apr 2023
Formatted: Friday, Apr 28, 2023

Date     : Monday, 22 May 2023
Formatted: Monday, May 22, 2023

 

Translate

Forum|alt.badge.img+1
  • Rookie
  • 2 replies
  • May 22, 2023

@Garrett  this works really nice! Thanks so much for your help!

Translate

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings