cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
eliotcole
Power Participant
Power Participant

Expression to Convert YYYY Only Year String into Date Format (ISO8601)

OK, so I can do it, but it's dirty, and feels wrong.

 

Basically, take the example of me having an array field that I need to use in a filter, and the date may simply be formatted as:

1983.

 

The formatDateTime function does not accept this. If it has Jan, January, or literally any other demarcation of a date around it, we are good, but a year on its own? Nope.

 

To make things simpler for working this out, let's just assume I have a variable called year, and that contains either something like March 1983, or just 1983.

 

Here's what I'm currently using ... and be forewarned ... it's a mess.

 

 

formatDateTime(if(and(contains('1234567890', substring(variables('year'), 0, 1)), equals(length(variables('year')), 4)), concat(variables('year'), '-01-01T00:00:00.0000000'), variables('year')))

 

 

 

So, with the above:

  1. It checks if the string is 4 characters long, AND if the first character is a number.
  2. If it is, it adds that to an acceptable rest of the ISO template.
  3. If it is not it just uses the date as is.

 

Let's ignore the fact that I could drop the formatDateTime from the above and still probably get something workable (the real world usage is to filter array items on this date field, so I want to be sure) ...

 

... is there a simpler function to illicit proper date data from just a YYYY value?

 

I mean, I need to know that externally of any context. If there is a 4 number string, is there a way of seeing that as a date in flow?

1 REPLY 1
v-bofeng-msft
Community Support
Community Support

Hi @eliotcole :

ISO 8601 Data elements and interchange formats – Information interchange – Representation of dates and times is an international standard covering the exchange of date- and time-related data.In view of the fact that power automate does not provide the function of directly and automatically converting the "year" in the form of a string to the date at 0:00 on the 1st of January of the current year, in the steps you provide, add'-01-01T00:00 to the "year" :00.0000000' is a necessary operation to comply with the ISO 8601 format.

Best Regards,

Bof

 

Helpful resources

Announcements
Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Top Solution Authors
Top Kudoed Authors
Users online (3,257)