Fri Dec 03, 2021 12:30 am
Login Register Lost Password? Contact Us


Is there anything out there for datetime calculations?

Comments and questions related to the Enterprise Control Language

Mon Dec 21, 2015 10:42 am Change Time Zone

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
Allan
 
Posts: 442
Joined: Sat Oct 01, 2011 7:26 pm

Mon Dec 21, 2015 2:29 pm Change Time Zone

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
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1606
Joined: Wed Oct 26, 2011 7:40 pm

Tue Dec 22, 2015 8:17 am Change Time Zone

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: 442
Joined: Sat Oct 01, 2011 7:26 pm

Tue Dec 22, 2015 3:07 pm Change Time Zone

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
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1606
Joined: Wed Oct 26, 2011 7:40 pm

Wed Nov 14, 2018 7:10 pm Change Time Zone

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
Allan
 
Posts: 442
Joined: Sat Oct 01, 2011 7:26 pm


Return to ECL

Who is online

Users browsing this forum: No registered users and 1 guest

cron