cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JoeVolk
Level: Powered On

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
Level 10

Re: Function to Find if Date is between 2 dates

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

Super User
Super User

Re: Function to Find if Date is between 2 dates

@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

6 REPLIES 6
EricLott
Level 10

Re: Function to Find if Date is between 2 dates

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

Super User
Super User

Re: Function to Find if Date is between 2 dates

@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

Dual Super User
Dual Super User

Re: Function to Find if Date is between 2 dates

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.
Highlighted
Super User
Super User

Re: Function to Find if Date is between 2 dates

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/

Community Support Team
Community Support Team

Re: Function to Find if Date is between 2 dates

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
Level: Powered On

Re: Function to Find if Date is between 2 dates

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!

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,532)