web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Expression to Convert ...
Power Automate
Unanswered

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

(0) ShareShare
ReportReport
Posted on by 4,390 Moderator

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?

Categories:
I have the same question (0)
  • v-bofeng-msft Profile Picture
    Microsoft Employee on at

    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

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 780

#2
Valantis Profile Picture

Valantis 668

#3
Haque Profile Picture

Haque 601

Last 30 days Overall leaderboard