difference b/w two date/time(contains weekno.) values - Unix

This is a discussion on difference b/w two date/time(contains weekno.) values - Unix ; Hi, I am using Solaris .... I want to have difference b/w to date/time into "hours:min" .... Both date values are in format of "YYwWK.WEEKNO - HH:MM" ( date '+%yw %V.%w - %H:%M' ) .... Can you please suggest me ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: difference b/w two date/time(contains weekno.) values

  1. difference b/w two date/time(contains weekno.) values

    Hi,
    I am using Solaris ....
    I want to have difference b/w to date/time into "hours:min" ....
    Both date values are in format of "YYwWK.WEEKNO - HH:MM" ( date '+%yw
    %V.%w - %H:%M' ) ....
    Can you please suggest me script code ... in shell script OR perl OR
    python....
    Thanks in advance...

  2. Re: difference b/w two date/time(contains weekno.) values

    On Tue, 16 Sep 2008, Bhavik wrote:
    > I am using Solaris ....
    > I want to have difference b/w to date/time into "hours:min"
    > .... Both date values are in format of "YYwWK.WEEKNO - HH:MM"
    > ( date '+%yw %V.%w - %H:%M' ) ....


    The general strategy:
    - convert both date-time to a number (number of seconds or ms
    after an epoch)
    - substract normally
    - change the difference to hh:mm format (should be easy to do
    manually, just calculate the number of minutes, div by 60 to
    get the hour and the remainder is the minutes).

    That said, the DateTime have different way to do it, as shown
    here:
    http://search.cpan.org/~drolsky/Date...me_Subtraction

    So for Perl, you can use several modules, among them:
    Date::Manip http://search.cpan.org/~sbeck/Date-Manip-5.54/
    DateTime http://search.cpan.org/~drolsky/DateTime-0.4304/
    (or http://datetime.perl.org/)

    For shell, check if your "date" command have option "-d" /
    "--date" as described below:

    -d, --date=STRING
    display time described by STRING, not °nowĘ

    Then you can use it to change the date to an epoch number as
    such:

    date --date "YYwWK.WEEKNO - HH:MM" +"%s"


    --
    (stephan paul) Arif Sahari Wibowo
    _____ _____ _____ _____
    /____ /____/ /____/ /____
    _____/ / / / _____/ http://www.arifsaha.com/

    Disclaimer: IANAL, IANALP, IANAMD, IANAMP, IANAAP
    my statements - if any - should be treated as such.

  3. Re: difference b/w two date/time(contains weekno.) values

    On 9/16/2008 2:11 AM, Bhavik wrote:
    > Hi,
    > I am using Solaris ....
    > I want to have difference b/w to date/time into "hours:min" ....
    > Both date values are in format of "YYwWK.WEEKNO - HH:MM" ( date '+%yw
    > %V.%w - %H:%M' ) ....
    > Can you please suggest me script code ... in shell script OR perl OR
    > python....
    > Thanks in advance...


    Here's a general approach in awk you can modify:

    function cvttime(t, a) {
    split(t,a,"[/:]")
    match("JanFebMarAprMayJunJulAugSepOctNovDec",a[2])
    a[2] = sprintf("%02d",(RSTART+2)/3)
    return( mktime(a[3]" "a[2]" "a[1]" "a[4]" "a[5]" "a[6]) )
    }
    BEGIN{
    t1="01/Dec/2005:00:04:42"
    t2="01/Dec/2005:17:14:12"
    print cvttime(t2) - cvttime(t1)
    }

    Add some "prints" to it and take a look at the GNU awk time functions
    (http://www.gnu.org/software/gawk/man...Time-Functions) to help you
    figure out what it does and how to modify it.

    Ed.


  4. Re: difference b/w two date/time(contains weekno.) values

    Hi All,
    Thanks for the suggestions, thanx again.... (" ,)

    On Sep 16, 6:09*pm, Ed Morton wrote:
    > On 9/16/2008 2:11 AM, Bhavik wrote:
    >
    > > Hi,
    > > I am using Solaris ....
    > > I want to have difference b/w to date/time into "hours:min" ....
    > > Both date values are in format of "YYwWK.WEEKNO - HH:MM" ( date '+%yw
    > > %V.%w - %H:%M' ) ....
    > > Can you please suggest me script code ... in shell script OR perl OR
    > > python....
    > > Thanks in advance...

    >
    > Here's a general approach in awk you can modify:
    >
    > function cvttime(t, * * a) {
    > * * * * split(t,a,"[/:]")
    > * * * * match("JanFebMarAprMayJunJulAugSepOctNovDec",a[2])
    > * * * * a[2] = sprintf("%02d",(RSTART+2)/3)
    > * * * * return( mktime(a[3]" "a[2]" "a[1]" "a[4]" "a[5]" "a[6]) )}
    >
    > BEGIN{
    > t1="01/Dec/2005:00:04:42"
    > t2="01/Dec/2005:17:14:12"
    > print cvttime(t2) - cvttime(t1)
    >
    > }
    >
    > Add some "prints" to it and take a look at the GNU awk time functions
    > (http://www.gnu.org/software/gawk/man...Time-Functions) to help you
    > figure out what it does and how to modify it.
    >
    > * * * * Ed.



+ Reply to Thread