KevinDS
(Kevin Da Silva)
August 15, 2019, 7:11pm
1
Hi, let me show you first what i’m doing to understand what i want to do…
I have 2 variables datetime types:
initDate=now
endDate=now.AddHours(2)
I’m writing in console with write line this result:
(endDate.Subtract(initDate)).ToString(“hh:mm:ss”)
This will gave me this result : 02:00:00
Now I’ve made some changes:
endDate=now.AddHours(2).addDays(2)
I was hoping to have this result → 50:00:00 (24 hours per day + 2 hours)
But instead I’ve received this → 02:00:00
It looks like is not reading difference between days.
Do you know what’s the right way to do have the complete hours between 2 days and 2 hours more?
Thank you a lot
@KevinDS
(endDate-initDate)
will give you the TimeSpan
between your two date times. The timespan is 2 days and 2 hours, so when you use the Hours
method you get 2. If you instead use TotalHours
it will count all hours in the TimeSpan
.
1 Like
KevinDS
(Kevin Da Silva)
August 15, 2019, 7:46pm
3
Hi @DanielMitchell thank you for the Reply
we’re almost there.
The problem with TotalHours is that creates a decimal.
if I put now this:
endDate=now.AddHours(2).addDays(2).addMinutes(-18)
it gaves me: 49,7xxxxxxxxxx (x means a lot of numbers)
When I need to have something like (“HH:mm:ss”) : 49:42:00
It’s like when you’re doing a countdown from one date to other date.
I’ll try to search like a countdown to know If I can found something…
Thank you
Dave
(David Wiebelhaus)
August 15, 2019, 7:58pm
4
@KevinDS - TotalHours is of course just going to provide the hours. It sounds like you want to get down to the minute. To do that get the timespan (i’ll call ts), but you’ll need 2 separate integer variables I’ll call hours and minutes. assign hours = Math.Floor(ts.TotalHours) and assign minutes = ts.Minutes. Now just print it out as write line = hours.tostring + “:” + minutes.tostring " + “:00”
2 Likes
KevinDS
(Kevin Da Silva)
August 15, 2019, 7:58pm
5
@DanielMitchell I’ve Got it!
I’ve been guide by this topyc And in “variable” I’ve put what you told me and work
If you don’t want the days and want total hours instead, use the TotalHours property of the timespan. (e.g. If the process takes 1 day, 12 hours, 15 minutes, and 12 seconds, you want the format of 36:15:12). Use something like this:
System.Math.Floor(variable.TotalHours).ToString & variable.ToString(“\:mm\:ss”)
1 Like
KevinDS
(Kevin Da Silva)
August 15, 2019, 8:01pm
6
Thank you @Dave Just at the same time but glad to have your help also
system
(system)
Closed
August 18, 2019, 8:01pm
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.