Ever had one of those days when you just can’t get the string to date conversion to work for your workflow?
I’ve seen a few questions on the forum about converting dates. Sometimes the format masks aren’t particularly intuitive, especially when coming to this new, which leads to time wasted by the person who just wants to make their workflow run without all the fuss!
The java-based format masks aren’t always obvious in their meaning, and it occurred to me that it would be nice if there were a way of handling a wide variety of date formats with a single mask, or some generic nodes and/or a tiny bit of generic code.
One of the problems is that if the month is a name rather than a number, the mask is unhelpful in being case-sensitive with respect to the data. So “Feb” will match the MMM mask, but “FEB” and “feb” will not. So some string manipulation would be required to accommodate this. Likewise people sometimes trip up by specifying dd when that “forces” a 2 digit day and refuses to accept a single digit day. Two and four digit years also cause a problem since yy matches ONLY 2 digit years while YYYY matches only 4 digit, and it isn’t always clear how to make it match both!
Another problem is that different people have a wide variety of ways to delimit the date components, and other “noise” can be added too.
I was looking at how we could have a format mask that could handle a wide variety of variations of dates which follow a similar basic format. Wouldn’t it be nice if we could have a piece of our workflow that could handle a wide variety of date formats within the same data set, provided that they conformed to a common order of component parts.
So say, for example we had a rule that the date was in D M Y order but beyond that we weren’t too fussed about exactly how it was presented…
… Wouldn’t it be nice if a single workflow with date conversion could handle all of these in a single flow:
I’ve put together a workflow containing a String Manipulation and a flexible date format mask, which makes use of optional features of the mask, and (in conjunction with the string manipulation) can handle all of those in the list above and more besides. The format mask can be manually adapted according to your locale and the workflow contains a second example that accepts dates in Month Day Year order too:
I did this as “a bit of fun” to see what could be done, but you may find it useful, especially if you have one of those of days where you just cannot get it to handle your date properly!
I might refine this a little and see if I can make it into a useful component!
(as it stands I realise this isn’t very “international”, and for non-English-language data you may need to adapt the code or mask slightly)