I need to format subtract 2 long date time result to "hh.mm.ss"
open date closed date subtracted
01/01/2012 16:04 04/01/2012 17:07 3.01:02:58
02/01/2012 08:52 02/01/2012 17:03 08:10:27
using
closeddate.subtract(opendate)
return result in format D.hh:mm:ss
and using
DateDiff("h", OpenDate, closeDate)
return hours only (no minutes or seconds)
Also tried
closeddate.subtract(opendate).tostring("hh:mm:ss")
not working
as many Microsoft forums answered there is no way to do that
so i used
DateDiff("s", OpenDate, closeDate)
and passed result to helper function return calculated time in format hh:mm:ss
Related
Converting a DateTime to unix convention using %s%L (%s means seconds since Jan 1st 1970, %L means to append 3 digits to represent milliseconds) give this:
DateTime.now.strftime '%s%L'
=> "1656279075654"
How can I get a DateTime back from this?
DateTime.strptime('1656279075654', '%s%L') gives an error, as strptime doesn't seem to know %L strangely.
secs = '1656279075654'.to_f / 1000
DateTime.strptime(secs.to_s, '%s')
or
DateTime.strptime('1656279075654', '%Q')
(%Q - number of milliseconds since 1970-01-01 00:00:00 UTC)
This question already has answers here:
date format function to display date as "Jan 13 2014"
(3 answers)
Closed 7 years ago.
I writing a code in VBScript, but I cannot get the datetime part right.
I'm using FormatDateTime(now), but the gives not the best result like
FormatDateTime(now)
8-01-2016 9:05:12 becomes 01-08-2016 9:05:12.
28-01-2016 19:01:18 stays 28-01-2016 19:01:18.
Has to be:
8-01-2016 9:05:12
28-01-2016 19:01:18
Is there a way to get both the same?
Try using the format argument of FormatDateTime.
FormatDateTime(now, 2) 'This should return in mm/dd/yy format
More info here.
http://www.w3schools.com/asp/func_formatdatetime.asp
format (Optional) A value that specifies the date/time format to use
Can take the following values:
0 = vbGeneralDate - Default. Returns date: mm/dd/yy and time if
specified: hh:mm:ss PM/AM.
1 = vbLongDate - Returns date: weekday,
monthname, year
2 = vbShortDate - Returns date: mm/dd/yy
3 =
vbLongTime - Returns time: hh:mm:ss PM/AM
4 = vbShortTime - Return
time: hh:mm
This should do what you want.
od = "28-01-2016 19:01:18"
nd = FormatDateTime(od,0)
MsgBox(nd)
Output: 1/28/2016 7:01:18 PM
How should I interpret all aspects of the following timestamps? Where is the time based and how do timezones apply?
2015-11-15T14:45:28Z
2015-11-15T14:45:28.9694Z
2015-11-15T14:45:28.969412345Z
Below is my thoughts...
Date: 2015-11-15
???: T
Hours: 14
Minutes: 45
Seconds: 28 OR 28.9694 OR 28.969412345
???: Z
Most of your values are attributed correctly. The date portion (2015-11-15) is in the order YYYY-MM-DD, time in HH:MM:SS.ffff.
T indicates the start of the time portion of the date time.
Z indicates the time zone is UTC. Next to Z, you could have a format like Z+02:00, which indicates the time zone is UTC + 2 hours.
Forgive me for my ignorance if its too easy and if its not the right place to post. I have 2 24 hours times strings as 1544 and 1458. Their difference should be 46 minutes but when I subtract them it yields 86 minutes as follows.
1544
-1458
-------
86
Can someone tell me how can I find a time difference of 2 24-hr times?
Hour doesn't have 100 minutes, but unfortunately only 60. You need to do this:
15*60+44
-14*60+58
---------
46
If you are working in C#, you can try to parse them to DateTime using
DateTime date1 = DateTime.ParseExact("1544","HHmm",CultureInfo.InvariantCulture);
DateTime date2 = DateTime.ParseExact("1458","HHmm",CultureInfo.InvariantCulture);
and then subtract them:
TimeSpan diff = date1 - date2
is there a Perl module which could give me for input month and year, let say, 06-2005, what the last day of this month for this year is? For this example, it is easy, because June always has 30 days, so the last day will be 30-06-2005. But it is not the case for February. So, if I have 02-1997, I would like to know whether to return 28-02-1997 or 29-02-1997. Thanks in advance.
Yes, there is a subroutine Days_in_Month in the Date::Calc module.
use strict;
use warnings;
use Date::Calc qw/Days_in_Month/;
for my $m (1 .. 12) {
print Days_in_Month(2005, $m), "\n";
}
OUTPUT
31
28
31
30
31
30
31
31
30
31
30
31
The last day in a given month is the "0th" day of the following month. mktime() takes a 0-based month and 1900-based year number, and returns an epoch timestamp.
use POSIX qw( mktime strftime );
sub last_day {
my ( $year, $mon ) = #_;
return mktime(0,0,0, 0, $mon, $year-1900);
}
You can pass that to localtime or strftime.
say scalar localtime last_day(2005, 5)
'Tue May 31 00:00:00 2005'
say scalar localtime last_day(2005, 6)
'Thu Jun 30 00:00:00 2005'
say scalar localtime last_day(1997, 2)
'Fri Feb 28 00:00:00 1997'
say scalar localtime last_day(2012, 2)
'Wed Feb 29 00:00:00 2012'
say (localtime last_day(1997, 2))[3]
'28'
say strftime "%d", localtime last_day(1997, 2)
'28'
As others said, use DateTime:
use DateTime;
my $dt = DateTime->last_day_of_month('year'=>2000, 'month'=>2);
print $dt->ymd; # '2000-02-29'
While DateTime may not be the fastest module for handling dates/times, it's definitely the most complete one. It's also the only one that handles the various quirks of date/time math correctly.