web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Half day calculation
Power Apps
Answered

Half day calculation

(0) ShareShare
ReportReport
Posted on by 36
Hi,
I am new to Power Apps and I'm building a leave request form for my office, but I am unable to calculate half days. This is a SharePoint form integrated with Power Apps.

 
 
 
and my coding is 
 
 RoundDown(DateDiff(DataCardValue28_1.SelectedDate, DataCardValue32_1.SelectedDate, TimeUnit.Days) / 7, 0) * 5 +
 Mod(5 + Weekday(DataCardValue32_1.SelectedDate) - Weekday(DataCardValue28_1.SelectedDate), 5)
 
Here's what I need help with:
  • If the user selects the same day for "From date" as AM and "To date" as AM, it should calculate 0.5 days.
  • If the user selects the same day for "From date" as PM and "To date" as PM, it should also calculate 0.5 days.
  • If the user selects the same day for "From date" as AM and "To date" as PM, it should calculate 1 day.
How can I implement this calculation? Any help would be greatly appreciated!
Thank you!
 
  
 
Categories:
I have the same question (0)
  • Micky Profile Picture
    365 Moderator on at
    Hello,
     
    Since we don't have hours to calculate you can try using the code below if it checks out for you.
     
    If(
        And(
            DataCardValue28_1.SelectedDate = DataCardValue32_1.SelectedDate,
            am_pmDropDown1.SelectedText.Value = am_pmDropDown2.SelectedText.Value
        ),
        0.5,
        If(
            And(
                DataCardValue28_1.SelectedDate = DataCardValue32_1.SelectedDate,
                am_pmDropDown1.SelectedText.Value <> am_pmDropDown2.SelectedText.Value
            ),
            1,
            RoundDown(
                DateDiff(
                    DataCardValue28_1.SelectedDate,
                    DataCardValue32_1.SelectedDate,
                    TimeUnit.Days
                ) / 7,
                0
            ) * 5 + Mod(
                5 + Weekday(DataCardValue32_1.SelectedDate) - Weekday(DataCardValue28_1.SelectedDate),
                5
            )
        )
    )
     
    Regards,
    MMPoweR
  • Verified answer
    Nirav Raval (Akira28) Profile Picture
    153 Moderator on at

    Even you can try the below code - 

    If(
        DataCardValue28_1.SelectedDate = DataCardValue32_1.SelectedDate,
        
        If(
            am_pmDropDown1.SelectedText.Value = am_pmDropDown2.SelectedText.Value,
            0.5, 
            1    
        ),
        
        RoundDown(
            DateDiff(
                DataCardValue28_1.SelectedDate,
                DataCardValue32_1.SelectedDate,
                TimeUnit.Days
            ) / 7, 0
        ) * 5 +
        Mod(
            5 + Weekday(DataCardValue32_1.SelectedDate) - Weekday(DataCardValue28_1.SelectedDate),
            5
        )
    )


    If this post solved your issue, clicking 'Does this answer your question' will help others discover the solution and close the topic. If you found it helpful, a Like would be awesome!


    Regards,
    Nirav J Raval (Akira28)
     
  • WW-25090315-0 Profile Picture
    36 on at
     
     


    Both of your answers are working; I can select 0.5 days, but I am unable to select leave for 1.5 days, 2.5 days, or 3.5 days.
    please help me How can I implement that calculation?
    Any help would be greatly appreciated!
    Thank you!


     
  • Verified answer
    Nirav Raval (Akira28) Profile Picture
    153 Moderator on at
    Try the below code - 
     

    If(
        DataCardValue28_1.SelectedDate = DataCardValue32_1.SelectedDate,
        
        If(
            am_pmDropDown1.SelectedText.Value = am_pmDropDown2.SelectedText.Value, 
            0.5,  
            1     
        ),
        
        RoundDown(
            DateDiff(
                DataCardValue28_1.SelectedDate,
                DataCardValue32_1.SelectedDate,
                TimeUnit.Days
            ) / 7, 0
        ) * 5 +
        Mod(
            5 + Weekday(DataCardValue32_1.SelectedDate) - Weekday(DataCardValue28_1.SelectedDate),
            5
        ) +
        
        
        If(
            am_pmDropDown1.SelectedText.Value = "PM",
            0.5,
            0    
        ) +
        If(
            am_pmDropDown2.SelectedText.Value = "AM",
            0.5, 
            0   
        )
    )

    I have update conditional logic to handle partial days (0.5) for the first and last day based on AM/PM selections, allowing for increments like 1.5, 2.5, or 3.5 days in addition to the original full-day or half-day calculations. 🤞


    If this post solved your issue, clicking 'Does this answer your question' will help others discover the solution and close the topic. If you found it helpful, a Like would be awesome!


    Regards,
    Nirav J Raval (Akira28)
  • WW-25090315-0 Profile Picture
    36 on at
     
    It's working Thank you very much
    highly appreciate this help
     
    Thank you again MMPoweR & Nirav (Akira28) both of you also

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard