I am trying to reformat input dates as string to a single format day/month/year, I try with the OOTB node string to date and it seems the input must be month/day/year otherwise it gets null result.
I would like to convert all strings to a list of dates day/month/year YYYY.
What I tried is to split the string with separator β/β and pick the first the second and third parts of it and build a new date, the difficulty to know what date starts with months instead of day, I would only know if the second pair of digits number is higher than 12 months. I think this is simple but looks a nightmare that perhaps there is direct smart solution using python.
I resolved it like this with OOTB nodes and it is a nightmare:
my first thought about this is that if you have everything in one list without having them sorted or some logic how they occured, it is impossible to reformat them. As shown above there is the date β08/10/21β that can be interpreted in two ways day/mounth and mounth/day.
At this point I see one solition that could be helpfull for you. It is to create two dates from one, so you donβt lose any information, but you get needless dates that you can theoretically get rid of.
we could consider by default date is starting by day/month and in rare cases it is with month/day which could be corrected if the second pair of digits is higher than number 12
from datetime import datetime #datum en tijd oproepen
now = datetime.now() #datum oproepen (is hierboven geimporteerd)
str_format = "%d-%m-%Y" #formaat van datum bepalen
datum = now.strftime(str_format) #nieuwe lijst maken met datum van vandaag
How would python ever know in what format the input date was given? @RubenVivancos his original post suggest there is a list with dates, in 3 different formats, if the day has a number below 12 its impossible to do if there are three options, right?
The suggestions here work but youd need a manual check for when both date and month number are interchangeable
if we have only two digits we are not able to identify if date is 1920 or 2020. Here we could put some restrictions letβs say if two digits are bigger than 22 then 19 will be instead of 20. Further distinguishing is not possible without knowing additional details.