cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ramanan89
Helper III
Helper III

Help with Date Picker

Hi all,

 

I am new to the community and powerapps. Need some help 🙂

 

I want the user to select only the date and time within next 3 days (72 hours), I have tried using April's code (Youtube) and tried making changes to it, but no luck.

 

The problem is, I want to restrict the selection of,

1. Saturday and Sunday 

2. Past dates

3. And Future dates beyond 3 days - Now only this works

 

This is how it looks like,

 

OnVisible property of form

 

 

 

If(
    Weekday(
        Today() + 3,
        StartOfWeek.Sunday
    ) = 1,
    Set(
        varDate,
        Today() + 4
    ),
    Weekday(
        Today() + 3,
        StartOfWeek.Sunday
    ) = 7,
    Set(
        varDate,
        Today() + 5
    ),
    Weekday(
        Today() + 3,
        StartOfWeek.Sunday
    ) <> 7 && Weekday(
        Today() + 3,
        StartOfWeek.Sunday
    ) <> 1,
    Set(
        varDate,
        Today() + 3
    )
)

 

 

 

and OnSelect of Submit button

 

 

 

If(
    DateValue2.SelectedDate > varDate,
    Set(
        varMessage,
        "Please select a date within 3 business days"
    ),
    SubmitForm(FormNewRequest);
    Set(
        varMessage,
        " "
    )
)

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
eka24
Super User III
Super User III

The formula you picked from April ensured tha variable deals with Weekend. So that portion is well taken care of.

However the issue now is the Past Date or Selecting weekend i tested:

If(DateValue2.SelectedDate < Today() Or
Weekday(DateValue2.SelectedDate)=1 Or
Weekday(DateValue2.SelectedDate)=7 Or
DateValue2.SelectedDate > varDate,
Notify("Please select a date within 3 business days Or Date which is not WeekEnd Or PastDates"),
SubmitForm(FormNewRequest))

 

 

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

 

View solution in original post

8 REPLIES 8
eka24
Super User III
Super User III

I tried with:

If(DateValue2.SelectedDate > varDate,
Notify("Please select a date within 3 business days"),

    SubmitForm(FormNewRequest))

 

it works fine

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Yeah it works, but the problem is it even selects old date and also weekends. 

I am want to exclude Weekends and past date. 🙂

Use
If(dteEndDate.SelectedDate < Today() Or dteEndDate.SelectedDate > varDate,
Notify("Please select a date within 3 business days"))
------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.
v-yutliu-msft
Community Support
Community Support

Hi @ramanan89 ,

The reason why your original formula not work is that:
you could directly add dates by using formula like this:

Today() + 3

You need to use DateAdd function to calculate on dates.

Try this formula:

 OnVisible property of form

If(
    Weekday(
        DateAdd(Today(),3,Days),
        StartOfWeek.Sunday
    ) = 1,
    Set(
        varDate,
        DateAdd(Today(),4,Days)
    ),
    Weekday(
       DateAdd(Today(),3,Days),
        StartOfWeek.Sunday
    ) = 7,
    Set(
        varDate,
       DateAdd(Today(),5,Days)
    ),
    Weekday(
        DateAdd(Today(),3,Days),
        StartOfWeek.Sunday
    ) <> 7 && Weekday(
        DateAdd(Today(),3,Days),
        StartOfWeek.Sunday
    ) <> 1,
    Set(
        varDate,
       DateAdd(Today(),3,Days)
    )
)

and OnSelect of Submit button

 

 

If(
    DateValue2.SelectedDate > varDate,
    Set(
        varMessage,
        "Please select a date within 3 business days"
    );Notify("Please select a date within 3 business days",NotificationType.Error),
    SubmitForm(FormNewRequest);
    Set(
        varMessage,
        " "
    )
)

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks. 🙂

But as mentioned earlier, this also works similarly.

 

The problem is, I want to restrict the selection of,

1. Saturday and Sunday 

2. Past dates

3. And Future dates beyond 3 days - Now only this works

eka24
Super User III
Super User III

The formula you picked from April ensured tha variable deals with Weekend. So that portion is well taken care of.

However the issue now is the Past Date or Selecting weekend i tested:

If(DateValue2.SelectedDate < Today() Or
Weekday(DateValue2.SelectedDate)=1 Or
Weekday(DateValue2.SelectedDate)=7 Or
DateValue2.SelectedDate > varDate,
Notify("Please select a date within 3 business days Or Date which is not WeekEnd Or PastDates"),
SubmitForm(FormNewRequest))

 

 

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

 

View solution in original post

royg
Advocate II
Advocate II

If you wish to maintain your original logics (some of the answers proposed better approaches), you only need to add a couple of IFs:

 

If(
Weekday(
Today() + 3,
StartOfWeek.Sunday
) = 1,
Set(
varDate,
Today() + 4
),
If(
Weekday(
Today() + 3,
StartOfWeek.Sunday
) = 7,
Set(
varDate,
Today() + 5
),
If(
Weekday(
Today() + 3,
StartOfWeek.Sunday
) <> 7 && Weekday(
Today() + 3,
StartOfWeek.Sunday
) <> 1,
Set(
varDate,
Today() + 3
)
)
)
)

 

HTH 

Thank you so much 🙂 This works!

Now I am facing another problem with time, as I have forgotten to validate that. Now I will have to add that to formula also. No worries. Thanks everyone for the help. 🙂

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (3,144)