cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
zizu
Frequent Visitor

Minus one time from another

Hi

I am trying to minus time from another, but I cannot do this from two labels. I was wondering if there was another way to do this? Thanks

 

PLEASE SEE ATTACHMENT.

 

Code for first time control:

 

 

 

 

    If(DateDiff(
        startDate.SelectedDate +
            Time(Value(startHour.SelectedText.Value), Value(startMinute.SelectedText.Value), 0),
        endDate.SelectedDate +
            Time(Value(endHour.SelectedText.Value), Value(endMinute.SelectedText.Value), 0),
        Minutes) < 0,
    "-", "") &

Text(
    Abs(
        DateDiff(
            startDate.SelectedDate +
                Time(Value(startHour.SelectedText.Value), Value(startMinute.SelectedText.Value), 0),
            endDate.SelectedDate +
                Time(Value(endHour.SelectedText.Value), Value(endMinute.SelectedText.Value), 0),
            Hours)),
    "[$-pt-BR]00") & ":" &
Text(
    Mod(
        Abs(
            DateDiff(
                startDate.SelectedDate +
                    Time(Value(startHour.SelectedText.Value), Value(startMinute.SelectedText.Value), 0),
                endDate.SelectedDate +
                    Time(Value(endHour.SelectedText.Value), Value(endMinute.SelectedText.Value), 0),
                Minutes)),
        60),
    "[$-pt-BR]00")

 

 

 

 

 

Second time control

 

 

 

 

    If(DateDiff(
        startDate_1.SelectedDate +
            Time(Value(startHour_1.SelectedText.Value), Value(startMinute_1.SelectedText.Value), 0),
        endDate_1.SelectedDate +
            Time(Value(endHour_1.SelectedText.Value), Value(endMinute_1.SelectedText.Value), 0),
        Minutes) < 0,
    "-", "") &

Text(
    Abs(
        DateDiff(
            startDate_1.SelectedDate +
                Time(Value(startHour_1.SelectedText.Value), Value(startMinute_1.SelectedText.Value), 0),
            endDate_1.SelectedDate +
                Time(Value(endHour_1.SelectedText.Value), Value(endMinute_1.SelectedText.Value), 0),
            Hours)),
    "[$-pt-BR]00") & ":" &
Text(
    Mod(
        Abs(
            DateDiff(
                startDate_1.SelectedDate +
                    Time(Value(startHour_1.SelectedText.Value), Value(startMinute_1.SelectedText.Value), 0),
                endDate_1.SelectedDate +
                    Time(Value(endHour_1.SelectedText.Value), Value(endMinute_1.SelectedText.Value), 0),
                Minutes)),
        60),
    "[$-pt-BR]00")

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@zahiriqbal ,

You need TimeValue and when you subtract them, you get milliseconds

With(
   {
      wTime: 
      (TimeValue(Label3.Text) - TimeValue(Label3_1.Text)) / 60000
   },
   Text(
      RoundDown(
         wTime / 60,
         0
      ),
      "00"
   ) & ":" & 
   Text(
      Mod(
         wTime,
         60
      ),
      "00"
   )
)

 

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.

Visit my blog Practical Power Apps

 

View solution in original post

7 REPLIES 7
WarrenBelz
Super User
Super User

Hi @zizu ,

Not sure on you exact logic here, but this structure should give you some guidance

With(
   {
      wDiff:
      DateDiff(
         startDate.SelectedDate +
         Time(
            Value(startHour.Selected.Value), 
            Value(startMinute.Selected.Value), 
            0
         ),
         endDate.SelectedDate +
         Time(
            Value(endHour.SelectedText.Value), 
            Value(endMinute.SelectedText.Value), 
            0
         ),
         Minutes
      )
   },
   If(
      wDiff < 0,
      "-",
      Text(
         Abs(
            RoundDown(wDiff/60,0)
         ),
         "[$-pt-BR]00"
      ) & ":" & 
      Text(
         Abs(
            Mod(wDiff,60)
         ),
         "[$-pt-BR]00"
      )
   )
)  

 

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.

Visit my blog Practical Power Apps

Hi

 

Basically if there are two labels with times in them like Label1(08:00) and Label2(00:30) how do i get a Label3(07:30) ?

 

Thanks

@zahiriqbal ,

I assume you are the same person ? I was responding to your post structure - it depends on where you get the data for the labels - I assumed you had a date picker and two drop-downs as per your post.

Yes, like the first post screenshot. So you have Clock in and Clock out and then lunch time. The times are output in lables. However if it could be done directly i would like to know how...thanks in advance.

 

e.g.

Time worked today: 09:00 - 17:00

Lunch time taken: 13:00 - 13:30

 

Total hours worked minus  lunch is 07:30

 

 

@zahiriqbal ,

Have you tried the code I posted off the date pickers and drop-downs ? I am not going to try off calculated labels when should be able to do it off the input.

Yes I tried your code and it works. However when i try to do the calucations using lables: DateDiff(DateTimeValue(Label3_1.Text),DateTimeValue(Label3.Text), Minutes)/60 

This works but im not getting the formatting correct and not sure if this is the best way to do it.

@zahiriqbal ,

You need TimeValue and when you subtract them, you get milliseconds

With(
   {
      wTime: 
      (TimeValue(Label3.Text) - TimeValue(Label3_1.Text)) / 60000
   },
   Text(
      RoundDown(
         wTime / 60,
         0
      ),
      "00"
   ) & ":" & 
   Text(
      Mod(
         wTime,
         60
      ),
      "00"
   )
)

 

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.

Visit my blog Practical Power Apps

 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (3,347)