cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Wrong Date Format in SharePoint List - Convert it and Filter to Right Date Format inside Automated Flow.

Hello,

 

I want to build a flow to notify users based on a field status in my SharePoint list, I know how to build this part. However I want to filter the amount of rows I check in the list, I want to filter by date as I have a field with a date but it is not formatted exactly as Date Time as it has more text. See screenshot below:

 

muhepd1_0-1696001101851.png

 

Is there a way the flow I am going to build converts the text in the Execution Date field to a Date Format (I cant change the format of the column), and then create the filter (to check only last 3 days) in the flow itself?

 

Could you show me how to do it please?

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions

Ok I have a way to get the date into the format and then filter the items.

 

Beginning Example of Expression to Format Date Time:

But the expressions will start getting long, so I want to show you the first part which is just getting the date into the correct format. This is not what the final flow will look like, but it is an example of what I'm going to be using.

 

I have made a SharePoint column and named it "ExecutionDate" and filled in some text similar to yours.

Example SharePoint ColumnExample SharePoint Column

 

So lets say all I wanted to do was to get the date formatted for each item. I would use the Get Items to retrieve all of the rows from the SharePoint List. Then I would add a Compose to the flow where I can make the expression.

Example for Formatting the Date TimeExample for Formatting the Date Time

 

In my example I'm using the expression:

 

 

 

parseDateTime(trim(first(split(item()?['ExecutionDate'],'-'))),'en-us','M/d/yy')

 

 

 

Working inwards to out this expression says:

  • split() - split the value where there is a '-' dash in the text string
  • first() - get the first part of the string that was split
  • trim() - remove any spaces from the text string
  • parseDateTime() - use the format 'M/d/yy' to read my value and convert it into datetime format

You can reference these functions here on Microsoft Learn Reference Guide

Here are a few of the item results with the datetime formatted.

Results of DateTime ConversionResults of DateTime Conversion

 

 

Can you make a similar example? Or do you understand what is happening to the string?

 

Basic Filter Query Example:

 

To filter the Get Items, you will have to use the "Filter Array" action. This will use the values from the Get Items and filter it by the conditions that are set. (After the filter array the rest of the data in the flow needs to reference the Filter Array as the source, not the Get Items.)

 

So lets say we want to filter the Get Items to have only items with an Execution Date that is greater than or equals 3 days from today. We will use the previous long expression of parseDateTime() to format the value, and compare it to the utcNow() function that gets the current time. If we include the addDays() function and add -3 days to utcNow() we will get 3 days before the current time.

Use the main ParseDateTime expression:

 

parseDateTime(trim(first(split(item()?['ExecutionDate'],'-'))),'en-us','M/d/yy')

 

is greater than or equal

Use the -3 days added to current time:

 

addDays(utcNow(),-3)

 

The Filter Array will look like the example below -

Basic Filter Array ExampleBasic Filter Array Example

 

But this isn't exactly accurate due to how UTC timezone and our formatted datetime are compared. Our formatted parseDateTime is midnight in our timezone. utcNow() is the current time of day. So by subtracting 3 days from the current time and comparing to our parseDateTime, the our values that are midnight 3 days ago would actually be not included since they are less than current time.

 

So to correct this, we need to convertTimeZone and set the time of day to midnight, and then subtract 3 days.

This is very similar to the previous Filter Array except the right side expression has been edited.

Use the main ParseDateTime expression:

 

parseDateTime(trim(first(split(item()?['ExecutionDate'],'-'))),'en-us','M/d/yy')

 

 is greater than or equal

Use the -3 days added to the converted timezone:

 

addDays(convertFromUtc(utcNow(),'Eastern Standard Time','yyyy-MM-dd'),-3)

 

The corrected Filter Array will look like the example below - 

Updated Basic Filter Array - Execution Date is greater or equal than 3 days agoUpdated Basic Filter Array - Execution Date is greater or equal than 3 days ago

 

So this is a basic Filter Array that will return items that are from -3 days ago using our formatted parseDateTime() value and the converted timezone value.

 

Advanced Mode - Edit Filter Array:

Since the filter array only allows 1 condition (the three boxes) in the basic mode, we need to switch it to advanced mode to get the complete filter.

Advanced Mode - Edit Filter Array conditionsAdvanced Mode - Edit Filter Array conditions

 

Click the Edit in Advanced Mode in the Filter Array and it will switch the boxes into the full expression code. So our 3 little boxes is actually the full expression:

 

@greaterOrEquals(parseDateTime(trim(first(split(item()?['ExecutionDate'], '-'))), 'en-us', 'M/d/yy'), addDays(convertFromUtc(utcNow(), 'Eastern Standard Time', 'yyyy-MM-dd'), -3))

 

 

Second Condition:

The reason we need a second condition, is because the single condition above will get every date that is above 3 days ago. So if there are dates that are next week or next year, they would be returned in the filter array. 

What we want to have is Get Executions Dates

  • Greater Than or Equals 3 Days Ago AND Less Than or Equals Today

Less Than or Equals Today

So to make the second expression that compares Execution Dates that are less Than or Equals Today. It is basically the first expression we used, except it does not need to subtract 3 days. And instead of greater than or equals we will use less than or equals. And since we need to be comparing to full dates instead of midnight time, I will edit the parseDateTime so that it matches the converted timezone.

 

If we made a filter array that just had the condition of get Execution Dates that are less Than or Equals Today it would look like the Filter Array below. And If we turn on advanced mode it will show what the expression will be.

Example Less Than or EqualsExample Less Than or Equals

The Expression that is used is:

 

@lessOrEquals(formatDateTime(parseDateTime(trim(first(split(item()?['ExecutionDate'], '-'))), 'en-us', 'M/d/yy'), 'yyyy-MM-dd'), convertFromUtc(utcNow(), 'Eastern Standard Time', 'yyyy-MM-dd'))

 

 Remove the '@' symbol at the beginning and this is the other condition we will use.

 

Completed Filter Array Condition:

So using all of the above we can make an advanced expression for the Filter Array that will get all Execution Dates that are Greater Than or Equals 3 days before today AND Less Than or Equals Today.

We basically combine the two large expressions with the and() function.

Greater Than or Equals 3 days before today:

 

greaterOrEquals(parseDateTime(trim(first(split(item()?['ExecutionDate'], '-'))), 'en-us', 'M/d/yy'), addDays(convertFromUtc(utcNow(), 'Eastern Standard Time', 'yyyy-MM-dd'), -3))

 

Less Than or Equals Today:

 

lessOrEquals(formatDateTime(parseDateTime(trim(first(split(item()?['ExecutionDate'], '-'))), 'en-us', 'M/d/yy'), 'yyyy-MM-dd'), convertFromUtc(utcNow(), 'Eastern Standard Time', 'yyyy-MM-dd'))

 

Full Combined Expression using the and() function:

 

@And(greaterOrEquals(parseDateTime(trim(first(split(item()?['ExecutionDate'], '-'))), 'en-us', 'M/d/yy'), addDays(convertFromUtc(utcNow(), 'Eastern Standard Time', 'yyyy-MM-dd'), -3)),lessOrEquals(formatDateTime(parseDateTime(trim(first(split(item()?['ExecutionDate'], '-'))), 'en-us', 'M/d/yy'), 'yyyy-MM-dd'), convertFromUtc(utcNow(), 'Eastern Standard Time', 'yyyy-MM-dd')))

 

 

It will look like this Filter Array below even though you can't see the full expression in advanced mode - 

Full Expression in Filter Array - (used photo edit to show full text box)Full Expression in Filter Array - (used photo edit to show full text box)

 

So I know I wrote a lot for this example, but I wanted to be sure that you understood how this built up into the large expression instead of just throwing something on here.

 

Let me know if this works for you,

View solution in original post

9 REPLIES 9

What TimeZone are you located?

 

Will any of these fields be ever be blank? Or will they always have values?

Eastern US Time (GMT - 4).

They will always have values.

 

Like the screenshot above, the string will show 9/23/23 - Day Time, meaning M or MM, DD, YY format.

Ok I have a way to get the date into the format and then filter the items.

 

Beginning Example of Expression to Format Date Time:

But the expressions will start getting long, so I want to show you the first part which is just getting the date into the correct format. This is not what the final flow will look like, but it is an example of what I'm going to be using.

 

I have made a SharePoint column and named it "ExecutionDate" and filled in some text similar to yours.

Example SharePoint ColumnExample SharePoint Column

 

So lets say all I wanted to do was to get the date formatted for each item. I would use the Get Items to retrieve all of the rows from the SharePoint List. Then I would add a Compose to the flow where I can make the expression.

Example for Formatting the Date TimeExample for Formatting the Date Time

 

In my example I'm using the expression:

 

 

 

parseDateTime(trim(first(split(item()?['ExecutionDate'],'-'))),'en-us','M/d/yy')

 

 

 

Working inwards to out this expression says:

  • split() - split the value where there is a '-' dash in the text string
  • first() - get the first part of the string that was split
  • trim() - remove any spaces from the text string
  • parseDateTime() - use the format 'M/d/yy' to read my value and convert it into datetime format

You can reference these functions here on Microsoft Learn Reference Guide

Here are a few of the item results with the datetime formatted.

Results of DateTime ConversionResults of DateTime Conversion

 

 

Can you make a similar example? Or do you understand what is happening to the string?

 

Basic Filter Query Example:

 

To filter the Get Items, you will have to use the "Filter Array" action. This will use the values from the Get Items and filter it by the conditions that are set. (After the filter array the rest of the data in the flow needs to reference the Filter Array as the source, not the Get Items.)

 

So lets say we want to filter the Get Items to have only items with an Execution Date that is greater than or equals 3 days from today. We will use the previous long expression of parseDateTime() to format the value, and compare it to the utcNow() function that gets the current time. If we include the addDays() function and add -3 days to utcNow() we will get 3 days before the current time.

Use the main ParseDateTime expression:

 

parseDateTime(trim(first(split(item()?['ExecutionDate'],'-'))),'en-us','M/d/yy')

 

is greater than or equal

Use the -3 days added to current time:

 

addDays(utcNow(),-3)

 

The Filter Array will look like the example below -

Basic Filter Array ExampleBasic Filter Array Example

 

But this isn't exactly accurate due to how UTC timezone and our formatted datetime are compared. Our formatted parseDateTime is midnight in our timezone. utcNow() is the current time of day. So by subtracting 3 days from the current time and comparing to our parseDateTime, the our values that are midnight 3 days ago would actually be not included since they are less than current time.

 

So to correct this, we need to convertTimeZone and set the time of day to midnight, and then subtract 3 days.

This is very similar to the previous Filter Array except the right side expression has been edited.

Use the main ParseDateTime expression:

 

parseDateTime(trim(first(split(item()?['ExecutionDate'],'-'))),'en-us','M/d/yy')

 

 is greater than or equal

Use the -3 days added to the converted timezone:

 

addDays(convertFromUtc(utcNow(),'Eastern Standard Time','yyyy-MM-dd'),-3)

 

The corrected Filter Array will look like the example below - 

Updated Basic Filter Array - Execution Date is greater or equal than 3 days agoUpdated Basic Filter Array - Execution Date is greater or equal than 3 days ago

 

So this is a basic Filter Array that will return items that are from -3 days ago using our formatted parseDateTime() value and the converted timezone value.

 

Advanced Mode - Edit Filter Array:

Since the filter array only allows 1 condition (the three boxes) in the basic mode, we need to switch it to advanced mode to get the complete filter.

Advanced Mode - Edit Filter Array conditionsAdvanced Mode - Edit Filter Array conditions

 

Click the Edit in Advanced Mode in the Filter Array and it will switch the boxes into the full expression code. So our 3 little boxes is actually the full expression:

 

@greaterOrEquals(parseDateTime(trim(first(split(item()?['ExecutionDate'], '-'))), 'en-us', 'M/d/yy'), addDays(convertFromUtc(utcNow(), 'Eastern Standard Time', 'yyyy-MM-dd'), -3))

 

 

Second Condition:

The reason we need a second condition, is because the single condition above will get every date that is above 3 days ago. So if there are dates that are next week or next year, they would be returned in the filter array. 

What we want to have is Get Executions Dates

  • Greater Than or Equals 3 Days Ago AND Less Than or Equals Today

Less Than or Equals Today

So to make the second expression that compares Execution Dates that are less Than or Equals Today. It is basically the first expression we used, except it does not need to subtract 3 days. And instead of greater than or equals we will use less than or equals. And since we need to be comparing to full dates instead of midnight time, I will edit the parseDateTime so that it matches the converted timezone.

 

If we made a filter array that just had the condition of get Execution Dates that are less Than or Equals Today it would look like the Filter Array below. And If we turn on advanced mode it will show what the expression will be.

Example Less Than or EqualsExample Less Than or Equals

The Expression that is used is:

 

@lessOrEquals(formatDateTime(parseDateTime(trim(first(split(item()?['ExecutionDate'], '-'))), 'en-us', 'M/d/yy'), 'yyyy-MM-dd'), convertFromUtc(utcNow(), 'Eastern Standard Time', 'yyyy-MM-dd'))

 

 Remove the '@' symbol at the beginning and this is the other condition we will use.

 

Completed Filter Array Condition:

So using all of the above we can make an advanced expression for the Filter Array that will get all Execution Dates that are Greater Than or Equals 3 days before today AND Less Than or Equals Today.

We basically combine the two large expressions with the and() function.

Greater Than or Equals 3 days before today:

 

greaterOrEquals(parseDateTime(trim(first(split(item()?['ExecutionDate'], '-'))), 'en-us', 'M/d/yy'), addDays(convertFromUtc(utcNow(), 'Eastern Standard Time', 'yyyy-MM-dd'), -3))

 

Less Than or Equals Today:

 

lessOrEquals(formatDateTime(parseDateTime(trim(first(split(item()?['ExecutionDate'], '-'))), 'en-us', 'M/d/yy'), 'yyyy-MM-dd'), convertFromUtc(utcNow(), 'Eastern Standard Time', 'yyyy-MM-dd'))

 

Full Combined Expression using the and() function:

 

@And(greaterOrEquals(parseDateTime(trim(first(split(item()?['ExecutionDate'], '-'))), 'en-us', 'M/d/yy'), addDays(convertFromUtc(utcNow(), 'Eastern Standard Time', 'yyyy-MM-dd'), -3)),lessOrEquals(formatDateTime(parseDateTime(trim(first(split(item()?['ExecutionDate'], '-'))), 'en-us', 'M/d/yy'), 'yyyy-MM-dd'), convertFromUtc(utcNow(), 'Eastern Standard Time', 'yyyy-MM-dd')))

 

 

It will look like this Filter Array below even though you can't see the full expression in advanced mode - 

Full Expression in Filter Array - (used photo edit to show full text box)Full Expression in Filter Array - (used photo edit to show full text box)

 

So I know I wrote a lot for this example, but I wanted to be sure that you understood how this built up into the large expression instead of just throwing something on here.

 

Let me know if this works for you,

Hi, thank you for this, I understand what you are doing, however I have an issue with the Expression.

 

When I am writing the expression, the 'ExecutionDate' you wrote, is it coming from the Dynamic content? Because when I try to find it, it is not there, I only get body and value from the Get items. Or are you bring that Dynamic content (ExecutionDate) from the first Compose?

 

As soon as I write parseDateTime the Dynamic content from the Get Items disappear:

muhepd1_0-1696008061081.png

 

I managed to make it work.

 

Now I need to tell my flow to only look for records from the 3 most recent days on the list

 

muhepd1_1-1696008284689.png

 

In regards to the Dynamic Content not appearing, that is annoying, but happens all of the time.

 

I am not using the outputs from the compose. However, I did use the compose to see what I needed to manually type into the expression. If you put the dynamic content into a compose by itself and then hover your mouse over it, then it will show you what is being used. Use that text within the expression.

 

I don't like how PA tries to be helpful and limit dynamic content options, but that is why it disappeared. The content is still available, if you manually type it in.

 

Basically you have to manually type it in.

Hi, I am going to mark your post as the solution, I made the filter array and it works. Thank you very much for that!

 

However, I hope you can continue helping me with something else from the same list.

 

Now I need to create a condition based on another column, if True I am going to send an email, when I add the condition in theory I should be bring the value of the other column from the filter array, do you know how can I do this please?

 

Thanks again!

So 2 things about continue working on this.

 

  1. Depending on the Condition, if it is easy enough, you could just add it to the Filter Array expression.
  2. I think you should make a separate post because I'm not going to be able to work on since I am about to leave. Make the post something like (Need Help Get Value From Filter Array and Check Condition), and show that you have a get items and Filter Array and then explain what you are trying to do.

If you want to look it up I think the best thing you could do would be to use a Select action from the Filter Array, and then use a Parse JSON action after the Select. (Now the Parse JSON would be the source, not the Filter Array.) 

Then use an Apply to Each on the body of the Parse JSON and you will be able to see the dynamic content options from the Parse JSON.

It would look something like this:

Filter Array - Select - Parse JSON - Apply to EachFilter Array - Select - Parse JSON - Apply to Each

 

So you can get something that looks similar to this and either look up info about these steps, or make a separate post. But this should get you in the direction you need to go.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,554)