Is there anything out there for datetime calculations?
Hi,
I have to find the difference between two datetimes (e.g. operands of the form YYYYMMDDHHMMSS)
I see a lot of support for date calculations but nothing for datetimes.
This is a very common thing to want to do, I'm sure I've just missed a post somewhere, if someone could just point me to a link I'd be very grateful. (I don't want to re-invent the wheel)
Yours
Allan
I have to find the difference between two datetimes (e.g. operands of the form YYYYMMDDHHMMSS)
I see a lot of support for date calculations but nothing for datetimes.
This is a very common thing to want to do, I'm sure I've just missed a post somewhere, if someone could just point me to a link I'd be very grateful. (I don't want to re-invent the wheel)
Yours
Allan
- Allan
- Posts: 444
- Joined: Sat Oct 01, 2011 7:26 pm
Allan,
Time support has fairly recently been added to the Date standard library, so take a look in the Date.ecl file in your eclibrary and see if any of the new time functions are helpful to you.
HTH,
Richard
Time support has fairly recently been added to the Date standard library, so take a look in the Date.ecl file in your eclibrary and see if any of the new time functions are helpful to you.
HTH,
Richard
- rtaylor
- Community Advisory Board Member
- Posts: 1619
- Joined: Wed Oct 26, 2011 7:40 pm
Nothing there, so knocked up my own, for use by others I reproduce below:
- Code: Select all
EXPORT STRING10 DateTimeDifference(STRING20 sd1,STRING20 sd2) := FUNCTION
// Input STRINGs 'YYYY-MM-DD HH:MM:SS'
// Output STRING 'HHHH:MM:SS' Note multiple days are just represetned as HHHH > 24
UNSIGNED8 SecondsSince1900(STRING20 dt) := FUNCTION
ASSERT(REGEXFIND('[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}',dt),'Passed Invalid datetime: '+dt,FAIL);
RETURN lib_date.dayssince1900((INTEGER2)dt[1..4],(INTEGER1)dt[6..7],(INTEGER1)dt[9..10])*86400
+((UNSIGNED8)dt[12..13])*3600
+((UNSIGNED8)dt[15..16])*60
+ (UNSIGNED8)dt[18..19];
END;
diff := ABS(SecondsSince1900(sd2)-SecondsSince1900(sd1));
RETURN INTFORMAT(diff DIV 3600,4,1)+':'+INTFORMAT((diff DIV 60) % 60,2,1)+':'+INTFORMAT(diff % 60,2,1);
END;
- Allan
- Posts: 444
- Joined: Sat Oct 01, 2011 7:26 pm
Allan,
Did you miss the CurrentSeconds() function? It returns the current date and time as the number of seconds since epoch (Jan 1, 1970).
HTH,
Richard
Did you miss the CurrentSeconds() function? It returns the current date and time as the number of seconds since epoch (Jan 1, 1970).
HTH,
Richard
- rtaylor
- Community Advisory Board Member
- Posts: 1619
- Joined: Wed Oct 26, 2011 7:40 pm
All,
Some STD functions are missing documentation, particularly 'STD.Date'.
Opened https://track.hpccsystems.com/browse/HPCC-20792 to get addressed.
Also a datetime difference function is being included in the STD.Date repertoire.
https://track.hpccsystems.com/browse/HPCC-20951
Yours
Allan
Some STD functions are missing documentation, particularly 'STD.Date'.
Opened https://track.hpccsystems.com/browse/HPCC-20792 to get addressed.
Also a datetime difference function is being included in the STD.Date repertoire.
https://track.hpccsystems.com/browse/HPCC-20951
Yours
Allan
- Allan
- Posts: 444
- Joined: Sat Oct 01, 2011 7:26 pm
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: Google [Bot] and 1 guest