cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Shaifu2K
Regular Visitor

Check for Duplicate Dates

So I'm currently building my first app which is a leave request app.

 

I have a SharePoint list where all the leave requests made in the app are stored. Every time a new request is made, a new row is added to the list. This list has a Start Date, End Date, and a Status column that tells if a request has been approved or rejected.

 

There are two date pickers in the app, one for the Start Date and another for the End Date. I want to validate these dates in such a way that the app will return an error if the dates selected and the dates between them already exist in a record in the SharePoint list with a pending or approved status.

1 ACCEPTED SOLUTION

Accepted Solutions

@Shaifu2K , 

So you have two date fields and want to see if either are within the period?

If(
   CountRows(
      Filter(
         YourDataSource,
         (
            YourStartDateField >= StartDateDatePicker.SelectedDate &&
            YourStartDateField <= EndDateDatePicker.SelectedDate
         ) ||
         (
            YourEndDateField >= StartDateDatePicker.SelectedDate &&
            YourEndDateField <= EndDateDatePicker.SelectedDate
         )
      )
   )>0,
   Notify("Date already taken",NotificationType.Error)
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

5 REPLIES 5
WarrenBelz
Super User III
Super User III

Hi @Shaifu2K ,

Something like this

If(
   CountRows(
      Filter(
         YourDataSource,
         YourDateField >= StartDateDatePicker.SelectedDate &&
         YourDateField <= EndDateDatePicker.SelectedDate
      )
   )>0,
   Notify("Date already taken",NotificationType.Error)
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

WarrenBelz
Super User III
Super User III

Hi @Shaifu2K ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @WarrenBelz ,

 

Sorry for the late reply.

Thanks for helping out! I have an issue with the code. It only works if the user-inputted start and end date match the dates in a record in the Sharepoint list.


For example, if a record in the Sharepoint list has a start and end date of Sept 25 to 26, the code will work if the user inputted Sept 25 and 26 as start end date in a request, but if the user inputted Sept 25 or 26 only as start and end date (meaning one day only) the code doesn't work.

 

@Shaifu2K , 

So you have two date fields and want to see if either are within the period?

If(
   CountRows(
      Filter(
         YourDataSource,
         (
            YourStartDateField >= StartDateDatePicker.SelectedDate &&
            YourStartDateField <= EndDateDatePicker.SelectedDate
         ) ||
         (
            YourEndDateField >= StartDateDatePicker.SelectedDate &&
            YourEndDateField <= EndDateDatePicker.SelectedDate
         )
      )
   )>0,
   Notify("Date already taken",NotificationType.Error)
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

This worked. Thanks very much!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (50,912)