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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Difference between two...
Power Apps
Unanswered

Difference between two date/time fields not right

(0) ShareShare
ReportReport
Posted on by 294

I have a screen where the user selects a Time In and Time Out. They select the Hour, Minute, and AM/PM in three different dropdowns for Time In and Time Out:

 

dBrand_0-1619910115097.png

I set three different fields to hold the date/time as below (DateIn, DateOutCk, DateOut). I then use the DateDiff between DateIn and DateOut to calculate the total 'Hours' (as below). The odd thing is when the screen loads (if it's a new record or pulling up an old one), the calculated field 'Hours' shows 32 hours, not 8 hours (which is the default when loaded - as in the picture above). But if the user changes the date, even slightly, it recalculates correctly. Not sure why this happens. Hopefully I explained this right. Maybe there's a better way. But I can't understand why this wouldn't work. If I highlight the code for DateOut it shows the right date and time, while it shows the wrong date, but right time in the field. I'm lost.

 

DateIn.text=

//Holds the Date In from the users selection (or loaded from the database).

DateTimeValue(Timesheet_Date.SelectedDate & " " & 'TimeInHour'.Selected.Value & ":" & 'TimeInMinutes'.Selected.Value & " " & 'TimeInAMPM'.Selected.Value)

 

DateOutCk= 

//Holds the Time Out, but using the Timesheet Selected Date (which is the same as the DateIn).

DateTimeValue(Timesheet_Date.SelectedDate & " " & 'TimeOutHour'.Selected.Value & ":" & 'TimeOutMinutes'.Selected.Value & " " & 'TimeOutAMPM'.Selected.Value)

 

DateOut=

//Checks to see if the Time Out is earlier than Time In.

//If so, assume it then carried into the next day, so add a day to the Date, but keep the Time Out the user selected.

If(TimeValue('DateOutCk'.Text) < TimeValue('DateIn'.Text),     
DateAdd(
DateTimeValue(Timesheet_Date.SelectedDate & " " & 'TimeOutHour'.Selected.Value & ":" & 'TimeOutMinutes'.Selected.Value & " " & 'TimeOutAMPM'.Selected.Value),
1,Days)
, //Else
DateTimeValue(Timesheet_Date.SelectedDate & " " & 'TimeOutHour_4'.Selected.Value & ":" & 'TimeOutMinutes'.Selected.Value & " " & 'TimeOutAMPM'.Selected.Value)
)

dBrand_1-1619910179900.png

 

Categories:
  • Sid_Jafri Profile Picture
    478 on at

    Hi @dBrand ,

     

    It seems that default Timeout values is set to next day 4:00PM, you should look for Default property and at the time of pulling the old record make sure default is your datasource value and if it is new then it must be same date 4:00 PM

     

    Please Thumbs up if my post helped you solve your issue.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 360 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 325

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard