Hello!
I've been trawling the forums trying to find a solution to this problem, but it seems a bit more complex than first envisioned.
I have a start date, formatted: "yyyy-dd-mm hh:mm:ss", I simply want to display a counter on the screen, showing the below (since the opened date).
- Months
- Days
- Hours
- Mins
E.G: "1 day, 12 hours, 43 minutes since the opened date"
Does anyone have any example code or advise they could share please?
Thanks in advanced!
Solved! Go to Solution.
I just noticed an error in my code where its still using
DatePicker1.SelectedDate
Make sure that all those entries get switched to 'myDate'. if your date is correct then it should work. It does in my test.
The key here is that you need to do each calculation recursively based on the previous calculation.
So to get Days it would be
DateDiff(StartDate,Now(),Days)
To get hours its the same calculation in Hours - the days * 24
With({DaysDiff:DateDiff(DatePicker1.SelectedDate,Now(),Days)* 24},Text(DateDiff(DatePicker1.SelectedDate,Now(),Hours)-DaysDiff,"[$-en-US]##0"))
And the minutes remaining uses the same pattern
With({MinutesDiff:DateDiff(DatePicker1.SelectedDate,Now(),Hours)* 60},Text(DateDiff(DatePicker1.SelectedDate,Now(),Minutes)-MinutesDiff,"[$-en-US]##0"))
Thanks for your reply, I tried this but it dosen't seem to give me the right result:
DateDiff(DateTimeValue(DataTable1.Selected.u_failure_time), Now(), Days) &
With({DaysDiff:DateDiff(DateTimeValue(DataTable1.Selected.u_failure_time), Now(), Days)* 24},Text(DateDiff(DateTimeValue(DataTable1.Selected.u_failure_time), Now(), Hours)-DaysDiff,"[$-en-US]##0")) &
With({MinutesDiff:DateDiff(DateTimeValue(DataTable1.Selected.u_failure_time),Now(),Hours)* 60},Text(DateDiff(DateTimeValue(DataTable1.Selected.u_failure_time),Now(),Minutes)-MinutesDiff,"[$-en-US]##0"))
DataTable1.Selected.u_failure_time = 2021-02-04 21:16:00
The result of this should be approx 32 days, 20 hours, 47 mins. The result on PowerApps is 33days, 3 hours and 13 mins.
Any further suggestions are welcomed!
If you want to concatenate the whole thing I would use Concatentate() and seperate each entry by commas rather than &. Like this:
With(
{myDate: DateTimeValue(DataTable1.Selected.u_failure_time)},
Concatenate(
Text(
DateDiff(
myDate,
Now(),
Days
)
),
" days, ",
With(
{
DaysDiff: DateDiff(
myDate,
Now(),
Days
) * 24
},
Text(
DateDiff(
myDate,
Now(),
Hours
) - DaysDiff,
"[$-en-US]##0"
)
),
" hours, ",
With(
{
MinutesDiff: DateDiff(
myDate,
Now(),
Hours
) * 60
},
Text(
DateDiff(
DatePicker1.SelectedDate,
Now(),
Minutes
) - MinutesDiff,
"[$-en-US]##0"
)
),
" seconds"
)
)
Thank you!
That calculates the days correct, but its still an issue with the hours and mins. The hours show -3 and the mins show 8, it should be approx 20hrs and 47mins.
Perhaps this is an issue with my date/time input's format?
I just noticed an error in my code where its still using
DatePicker1.SelectedDate
Make sure that all those entries get switched to 'myDate'. if your date is correct then it should work. It does in my test.
User | Count |
---|---|
159 | |
96 | |
82 | |
74 | |
58 |
User | Count |
---|---|
194 | |
178 | |
102 | |
95 | |
85 |