cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JoeVolk
Helper I
Helper I

Function to Find if Date is between 2 dates

I am trying to create a collection from a SharePoint list. The list includes upcoming IT outages as well as old outages. What I want to do is see if the current date/time is between a start and end date/time. Once I can do that compare, I would then show or hide icons to let the user know if we are currently experiencing an outage. If no outages are in the list for the current time, i would show a green checkmark; if we are in a partial outage, a yellow icon; completely down would show a red icon.

 

So my current issue is being able to get a collection of submitted outages from the SharePoint list where the current date/time is between the user submitted start/end date and time. Thanks!

2 ACCEPTED SOLUTIONS

Accepted Solutions
EricLott
Community Champion
Community Champion

You could use a formula like this

 

Filter(YourDateSource,Now()>BegDate,Now()<EndDate)

 

Where YourDataSource is you SharePoint List, BegDate is the column with the outage start datetime, and EndDate is the column with the outage end datetime.

You could also do this as a calculated column on your SharePoint list to simplify the PowerApps side and make future development easier when this is needed.

View solution in original post

mdevaney
Super User
Super User

@JoeVolk 

You can use this code to create a Collection that shows only current outages.

 

ClearCollect(
    myCollectionName,
    Filter(
        your_SharePoint_list,
        Now() >= UserStartDateTime,
        Now() <= UserEndDateTime
    )
)

 

Note: @EricLott and I must have posted at the same time.  At least we came to the same conclusion.

---

Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

7 REPLIES 7
EricLott
Community Champion
Community Champion

You could use a formula like this

 

Filter(YourDateSource,Now()>BegDate,Now()<EndDate)

 

Where YourDataSource is you SharePoint List, BegDate is the column with the outage start datetime, and EndDate is the column with the outage end datetime.

You could also do this as a calculated column on your SharePoint list to simplify the PowerApps side and make future development easier when this is needed.

mdevaney
Super User
Super User

@JoeVolk 

You can use this code to create a Collection that shows only current outages.

 

ClearCollect(
    myCollectionName,
    Filter(
        your_SharePoint_list,
        Now() >= UserStartDateTime,
        Now() <= UserEndDateTime
    )
)

 

Note: @EricLott and I must have posted at the same time.  At least we came to the same conclusion.

---

Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Pstork1
Dual Super User
Dual Super User

Both @mdevaney and @EricLott make good suggestions.  The one thing I would add is to take the Timezone into account.  The date you retrieve from SharePoint will be based on the location of the data center where your server resides, unless someone has modified the regional settings for the site collection.  Not having everything in the same timezone can really throw off your calculations since the current date/time will be in either UTC or your local timezone.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Join me at 365 and PWR EduCon in Chicago
EduCon Chicago 2022

Excellent advice @Pstork1.

 

I will also mention that DateTime objects currently cannot be delegated in SharePoint while using FILTER.  Check this blog post for full details.

https://powerapps.microsoft.com/en-us/blog/sharepoint-delegation-improvements/

v-xida-msft
Community Support
Community Support

Hi @JoeVolk ,

Do you want to get a collection of submitted outages from the SP list where current date/time is between the user submitted start/end date and time?

 

I have made a test on my side, please consider take a try with the following workaround:

Set the OnStart property of App to following:

ClearCollect(
             ExpectedCollection,
             Filter(
                    'YourSPList', 
                    Value(Text('Start Time', "yyyymmddHHmm")) < Value(Text(Now(), "yyyymmddHHmm")),
                   Value(Text('End Time', "yyyymmddHHmm")) > Value(Text(Now(), "yyyymmddHHmm")) 
             )
)

then re-load your app (fire the OnStart property of App), then check if the issue is solved.

Note: Please also make sure you have set the "Data row limit for Non-delegable queries" option within Advanced settings of App settings of your app.

 

After that, you could use the ExpectedCollection as data source in your app, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
JoeVolk
Helper I
Helper I

Great suggestions everyone! I was able to get this working. I will take some of the other suggestions into account to make sure I have this functioning at the highest level so we have no bad data for our users.

 

Thanks again!

Agree with @EricLott 's solution, except I had syntax errors if the argument on the left side of the greater/less than was not my variable. So I had to rearrange formula like the sample below:

Filter(YourDateSource,BegDate<Now(),EndDate<Now())

 

Very helpful, thanks all!

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (3,685)