VBA subtract date and times
By : palindromicPrimes
Date : March 29 2020, 07:55 AM
may help you . code :
Sub Test()
Dim dtmStart As Date, dtmEnd As Date, dblDuration As Double
dtmStart = "1900/01/01 08:10:00"
dtmEnd = "1900/01/03 21:16:00"
dblDuration = dtmEnd - dtmStart
MsgBox Application.Text(dblDuration, "[hh]:mm")
End Sub
|
Why can't I subtract 3 times?
By : tuhin
Date : March 29 2020, 07:55 AM
Hope that helps You can't subtract a time from a duration. For instance, nine minutes minus one o'clock is meaningless. Here you have $t1 equals 10:15am, and $t2 equals 17:30 or 5:30pm. So $t2 - $t1 is the time between them, or 7.25 hours. code :
use strict;
use warnings;
use Time::Seconds;
my $t1 = Time::Seconds->new(10 * ONE_HOUR + 15 * ONE_MINUTE); # 10:15
my $t2 = Time::Seconds->new(17 * ONE_HOUR + 30 * ONE_MINUTE); # 17:30
my $t3 = Time::Seconds->new( 7 * ONE_HOUR + 24 * ONE_MINUTE); # 7:24
my $t = $t2 - $t1 - $t3;
print $t->minutes, "\n";
-9
use strict;
use warnings;
use Time::Piece;
use constant MIDNIGHT => Time::Piece->strptime('00:00', '%H:%M');
my $t1 = Time::Piece->strptime( '10:15', '%H:%M' );
my $t2 = Time::Piece->strptime( '17:30', '%H:%M' );
my $t3 = Time::Piece->strptime( '7:24', '%H:%M' );
$_ -= MIDNIGHT for $t1, $t2, $t3;
my $t = $t2 - $t1 - $t3;
print $t->minutes;
use strict;
use warnings;
use Time::Piece;
use Time::Seconds;
use constant MIDNIGHT => Time::Piece->strptime('00:00', '%H:%M');
my $t1 = new_duration('10:15');
my $t2 = new_duration('17:30');
my $t3 = new_duration( '7:24');
my $t = $t2 - $t1 - $t3;
print $t->minutes;
sub new_duration {
Time::Piece->strptime(shift, '%H:%M') - MIDNIGHT;
}
-9
|
How To Subtract two times
By : user2485119
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Hi guys , Another way using the TimeSpan class. code :
Dim timeIn As String = "12:10"
Dim timeOut As String = "15:20"
MessageBox.Show(TimeSpan.Parse(timeOut).Subtract(TimeSpan.Parse(timeIn)).ToString(("hh\:mm")))
|
How to subtract 2 times with moment.js, then subtract some minutes
By : Jimmmy codeing
Date : March 29 2020, 07:55 AM
hop of those help? I need to subtract 2 times with moment.js (get the difference), and then with that result, subtract some additional minutes (simple int). It's for calculating timesheets. A few examples: code :
// parse time using 24-hour clock and use UTC to prevent DST issues
var start = moment.utc(startTime, "HH:mm");
var end = moment.utc(endTime, "HH:mm");
// account for crossing over to midnight the next day
if (end.isBefore(start)) end.add(1, 'day');
// calculate the duration
var d = moment.duration(end.diff(start));
// subtract the lunch break
d.subtract(30, 'minutes');
// format a string result
var s = moment.utc(+d).format('H:mm');
|
subtract n times int value
By : Sczerina Hobday
Date : March 29 2020, 07:55 AM
it helps some times It looks like the goal here is to subtract all 5 numbers from quan. The code in question subtracts only the last one. To subtract all numbers, initialize the result variable to the first number: code :
op = quan;
op = op - numbers; // alternatively: op -= numbers
|