Skip to main content

I needed it, others needed it and it isn't in the NWC Toolkit yet. So, we'll have to do it ourselves for now: Convert a date in text format into a date variable.

Here is how it goes:

  • For this example we assume the text date is in the ddmmyyyy format. In the code below you'll see how to change it for other formats.
  • It's sad that we have to (ab)use a component workflow for this but until there is a decent action that does it we'll have to do it this way I guess.
  • Input for the component workflow : a text variable with a date in ddmmyyyy format 
  • Output: a date type variable (ignore the time part as we all live in different time zones)

Here is the sequence of actions:

24370i8DE8C6557E5F208D.png

The trick is that we use 1-1-2020 as a reference date to add the difference in days and months from the input. The actions with the green numbers are explained in detail below.

 

First create a new component workflow and define your variables:

24379iC352305D51A47638.png

Workflow variables:

24380i86EA82DBD0642A35.png

The numbered actions in detail:

24371iD27239E67BCAD3AC.png

0 is the position where the day starts.

2 is the number of characters for the day.

Month will 2 and 2 and year will be 4 and 4.

For other formats just change the positions.

24372i5FE3908E758E8DD5.png

24373i3786C90DB28DA69C.png

24374i08E723DEEB7450EB.png

24375i5AA9C00EFB7F0FED.png

24376i7467AE61B5A46AA9.png

24377i66540A9CC928AF3E.png

24378iC4704A4EAD8308D9.png

Make sure to test it before use. No warranty. But it works for me.

Thank you for sharing! 


It looks like your scenario is for a string containing a date that does not originate from a form.  If you are capturing a date as a string on a form, you can create a form variable that uses the convertToDate function and reference it in the workflow.


Correct @DavidL2. But in my case this is data from an external source needing to be processed.


@WouterT 



This is, unfortunately, what we're having to do in a few of our workflows as well. 



 



We're using the "Apply a regular expression" action to parse the input date into a collection, then 3 "Get Item from Collection" actions to pull the month, day, and year out of the collection. It saves a couple actions since all 3 pieces are extracted by 1 action instead of 3 "modify string" actions.  If your input date uses a format where all the pieces are two digits long (071322) or separated by a delimiter (7/13/22), the following regular expression setup would work:





Result with "Test" collection logged to instance details:





 



That being said, if I was going to make a component workflow out of it I'd use your method and have the index/length of each piece be passed along as well. That way it could be used with all different date formats, other than when single digit days/months are possible (7 instead of 07 for July).



 



Hopefully the action they're working on will be finished soon so this isn't necessary.


SOLVED! Thank you, Nintex, for adding this into the Sept. 30, 2022 release in the Convert a Value action. No more tricks as any of the above mentioned necessary.




Isn’t working as expected. Note date is printed as “27/09/2024” :

 

 

I have tried this:

 

and this (note the quotes) :

 

this:

 

this with capital D’s : 

 

None of them work and all give the same error.

 

Any suggestions?

 


Reply