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

Calendar Problem

Hi all, 

 

Image.png

 

 

 

 

 

 

 

 

 

 

 

 

 

My No of Days for leave request app calendar does not work properly. IT does not show the proper number. Leave date is April 20 and Return date is 22 April. It should show 2 days but rather 172800000. Also, how do I make Saturday and Sunday as public holiday and if leave is taken on the same day for example leave date is April 20 and return date is April 20, how to make it 0.5?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @HF306,

I just give you choices to select, you should combine these as conditions in an If statement.

Modify your Default property as below:

If(
    DateDiff(
        DatePicker1.SelectedDate,
        DatePicker2.SelectedDate,
        Days
    ) = 0,
    0.5,
    RoundDown(
        DateDiff(
            DatePicker1.SelectedDate,
            DatePicker2.SelectedDate,
            Days
        ) / 7,
        0
    ) * 5 + Mod(
        5 + Weekday(DatePicker2.SelectedDate) - Weekday(DatePicker1.SelectedDate),
        5
    )
)

Qi

Best Regards,
Qi

View solution in original post

4 REPLIES 4
v-qiaqi-msft
Community Support
Community Support

Hi @HF306,

Could you please share a bit more about your scenario, how you set the Default of the Text input corresponding to the No of Days data card?

Note that DatePicker1 represents the start date and the DatePicker2 represents the end date.

1). Do you want to calculate the days difference between two dates?

Generally, we calculate the date difference using the DateDiff() function.

For your scenario, please try the formula as below:

DateDiff(DatePicker1.SelectedDate,DatePicker2.SelectedDate,Days)

2). Do you want to calculate the days difference between two dates excluding weekends?

RoundDown(
    DateDiff(
        DatePicker1.SelectedDate,
        DatePicker2.SelectedDate,
        Days
    ) / 7,
    0
) * 5 + Mod(
    5 + Weekday(DatePicker2.SelectedDate) - Weekday(DatePicker1.SelectedDate),
    5
)

3). Do you want to make it 0.5 day if the user leave and return at the same day?

If(DateDiff(DatePicker1.SelectedDate,DatePicker2.SelectedDate,Days)=0,"0.5")

Hope it could help.

Regards,

Qi

 

Best Regards,
Qi
HF306
Helper I
Helper I

Hi @v-qiaqi-msft , 

 

Image.png

 

Number 3 works, I entered the function at Default. Thank you so much!

 

Where do I enter the function for Number 1 and Number 2?

 

My Start date is DataCardValue_LeaveDate and Leave date is DataCardValue_ReturnDate.

 

Hi @HF306,

I just give you choices to select, you should combine these as conditions in an If statement.

Modify your Default property as below:

If(
    DateDiff(
        DatePicker1.SelectedDate,
        DatePicker2.SelectedDate,
        Days
    ) = 0,
    0.5,
    RoundDown(
        DateDiff(
            DatePicker1.SelectedDate,
            DatePicker2.SelectedDate,
            Days
        ) / 7,
        0
    ) * 5 + Mod(
        5 + Weekday(DatePicker2.SelectedDate) - Weekday(DatePicker1.SelectedDate),
        5
    )
)

Qi

Best Regards,
Qi

oh okay, it worked!! thank you so much qi !!!

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PWREduCon768x460.png

Join us at PWR EduCon - A Power Platform Conference

Learn from the top Power BI, Power Apps, Power Automate & Power Virtual Agents experts!

Top Solution Authors
Top Kudoed Authors
Users online (3,197)