ksh - subtract 5 minutes from current time

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I need to get the date and time of the command date minus 5 mins.



date:
29 Aug 2018 21:56:01

result:
29 Aug 2018 21:51:02


I tried to search on the Internet/forums but most of it involved using the -d option and what I have doesn't support the -d option.



This one works on Bash but I need something that works on ksh.



$ printf "%(%d %h %Y %H:%M:%S)Tn" $(( $(printf "%(%s)T") - 5 * 60 ))






share|improve this question






















  • What ksh version do you have? ksh --version. And can you also use perl or python?
    – chaos
    Sep 3 at 5:34










  • ksh --version is not working for me. I can use perl.
    – WaldenSchmidt
    Sep 3 at 5:43










  • chaos is indulging in a little GNU Think. (-: The PD Korn shell does not support --version. Neither does the MirBSD Korn shell. The bigger clue as to whether one is using 93 Korn is the 93 in the name of the command, ksh93 as it usually is, not ksh as chaos said (which is PD Korn on several operating systems, not 93 Korn).
    – JdeBP
    Sep 3 at 10:44










  • Why are you demonstrating a 4:59 difference when the title says 5 minutes?
    – Jeff Schaller
    Sep 3 at 11:47














up vote
3
down vote

favorite












I need to get the date and time of the command date minus 5 mins.



date:
29 Aug 2018 21:56:01

result:
29 Aug 2018 21:51:02


I tried to search on the Internet/forums but most of it involved using the -d option and what I have doesn't support the -d option.



This one works on Bash but I need something that works on ksh.



$ printf "%(%d %h %Y %H:%M:%S)Tn" $(( $(printf "%(%s)T") - 5 * 60 ))






share|improve this question






















  • What ksh version do you have? ksh --version. And can you also use perl or python?
    – chaos
    Sep 3 at 5:34










  • ksh --version is not working for me. I can use perl.
    – WaldenSchmidt
    Sep 3 at 5:43










  • chaos is indulging in a little GNU Think. (-: The PD Korn shell does not support --version. Neither does the MirBSD Korn shell. The bigger clue as to whether one is using 93 Korn is the 93 in the name of the command, ksh93 as it usually is, not ksh as chaos said (which is PD Korn on several operating systems, not 93 Korn).
    – JdeBP
    Sep 3 at 10:44










  • Why are you demonstrating a 4:59 difference when the title says 5 minutes?
    – Jeff Schaller
    Sep 3 at 11:47












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I need to get the date and time of the command date minus 5 mins.



date:
29 Aug 2018 21:56:01

result:
29 Aug 2018 21:51:02


I tried to search on the Internet/forums but most of it involved using the -d option and what I have doesn't support the -d option.



This one works on Bash but I need something that works on ksh.



$ printf "%(%d %h %Y %H:%M:%S)Tn" $(( $(printf "%(%s)T") - 5 * 60 ))






share|improve this question














I need to get the date and time of the command date minus 5 mins.



date:
29 Aug 2018 21:56:01

result:
29 Aug 2018 21:51:02


I tried to search on the Internet/forums but most of it involved using the -d option and what I have doesn't support the -d option.



This one works on Bash but I need something that works on ksh.



$ printf "%(%d %h %Y %H:%M:%S)Tn" $(( $(printf "%(%s)T") - 5 * 60 ))








share|improve this question













share|improve this question




share|improve this question








edited Sep 3 at 6:06









slm♦

237k65486659




237k65486659










asked Sep 3 at 4:46









WaldenSchmidt

182




182











  • What ksh version do you have? ksh --version. And can you also use perl or python?
    – chaos
    Sep 3 at 5:34










  • ksh --version is not working for me. I can use perl.
    – WaldenSchmidt
    Sep 3 at 5:43










  • chaos is indulging in a little GNU Think. (-: The PD Korn shell does not support --version. Neither does the MirBSD Korn shell. The bigger clue as to whether one is using 93 Korn is the 93 in the name of the command, ksh93 as it usually is, not ksh as chaos said (which is PD Korn on several operating systems, not 93 Korn).
    – JdeBP
    Sep 3 at 10:44










  • Why are you demonstrating a 4:59 difference when the title says 5 minutes?
    – Jeff Schaller
    Sep 3 at 11:47
















  • What ksh version do you have? ksh --version. And can you also use perl or python?
    – chaos
    Sep 3 at 5:34










  • ksh --version is not working for me. I can use perl.
    – WaldenSchmidt
    Sep 3 at 5:43










  • chaos is indulging in a little GNU Think. (-: The PD Korn shell does not support --version. Neither does the MirBSD Korn shell. The bigger clue as to whether one is using 93 Korn is the 93 in the name of the command, ksh93 as it usually is, not ksh as chaos said (which is PD Korn on several operating systems, not 93 Korn).
    – JdeBP
    Sep 3 at 10:44










  • Why are you demonstrating a 4:59 difference when the title says 5 minutes?
    – Jeff Schaller
    Sep 3 at 11:47















What ksh version do you have? ksh --version. And can you also use perl or python?
– chaos
Sep 3 at 5:34




What ksh version do you have? ksh --version. And can you also use perl or python?
– chaos
Sep 3 at 5:34












ksh --version is not working for me. I can use perl.
– WaldenSchmidt
Sep 3 at 5:43




ksh --version is not working for me. I can use perl.
– WaldenSchmidt
Sep 3 at 5:43












chaos is indulging in a little GNU Think. (-: The PD Korn shell does not support --version. Neither does the MirBSD Korn shell. The bigger clue as to whether one is using 93 Korn is the 93 in the name of the command, ksh93 as it usually is, not ksh as chaos said (which is PD Korn on several operating systems, not 93 Korn).
– JdeBP
Sep 3 at 10:44




chaos is indulging in a little GNU Think. (-: The PD Korn shell does not support --version. Neither does the MirBSD Korn shell. The bigger clue as to whether one is using 93 Korn is the 93 in the name of the command, ksh93 as it usually is, not ksh as chaos said (which is PD Korn on several operating systems, not 93 Korn).
– JdeBP
Sep 3 at 10:44












Why are you demonstrating a 4:59 difference when the title says 5 minutes?
– Jeff Schaller
Sep 3 at 11:47




Why are you demonstrating a 4:59 difference when the title says 5 minutes?
– Jeff Schaller
Sep 3 at 11:47










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










You could use perl:



echo $(( $(printf "%(%s)T") - 5 * 60 )) | perl -lne 'print scalar localtime $_'


Or in pure perl:



perl -le 'print scalar localtime(time()-5*60)'


To format use strftime():



perl -MPOSIX=strftime -le 'print strftime("%d %h %Y %H:%M:%S", localtime(time()-5*60))'





share|improve this answer






















  • The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
    – WaldenSchmidt
    Sep 3 at 6:05











  • @WaldenSchmidt see my edit
    – chaos
    Sep 3 at 6:08










  • Thanks man! This is perfect!
    – WaldenSchmidt
    Sep 3 at 6:09

















up vote
5
down vote













bash actually copied the %(...)T format from ksh93 but only a small subset.



That's much more powerful in ksh93.



$ date; printf '%(%c)Tn' 'exactly five minutes ago'
Mon 3 Sep 08:08:32 BST 2018
Mon Sep 3 08:03:32 2018


bash only supports Unix epoch times (or -1 for now, though with recent versions you can also get now with a missing argument) while ksh93 supports complex relative (including English like above, crontab, at, ISO 8601:2004 durations) or absolute time specifications (see the test data in the source for some examples).



In ksh93, if you want to pass an epoch time, you use a # prefix:



$ printf '%(%c)Tn' '#0'
Thu Jan 1 00:00:00 1970


(though here, it happens to give the incorrect time for me in a British timezone where epoch time 0 was at 1am)






share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466487%2fksh-subtract-5-minutes-from-current-time%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    You could use perl:



    echo $(( $(printf "%(%s)T") - 5 * 60 )) | perl -lne 'print scalar localtime $_'


    Or in pure perl:



    perl -le 'print scalar localtime(time()-5*60)'


    To format use strftime():



    perl -MPOSIX=strftime -le 'print strftime("%d %h %Y %H:%M:%S", localtime(time()-5*60))'





    share|improve this answer






















    • The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
      – WaldenSchmidt
      Sep 3 at 6:05











    • @WaldenSchmidt see my edit
      – chaos
      Sep 3 at 6:08










    • Thanks man! This is perfect!
      – WaldenSchmidt
      Sep 3 at 6:09














    up vote
    2
    down vote



    accepted










    You could use perl:



    echo $(( $(printf "%(%s)T") - 5 * 60 )) | perl -lne 'print scalar localtime $_'


    Or in pure perl:



    perl -le 'print scalar localtime(time()-5*60)'


    To format use strftime():



    perl -MPOSIX=strftime -le 'print strftime("%d %h %Y %H:%M:%S", localtime(time()-5*60))'





    share|improve this answer






















    • The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
      – WaldenSchmidt
      Sep 3 at 6:05











    • @WaldenSchmidt see my edit
      – chaos
      Sep 3 at 6:08










    • Thanks man! This is perfect!
      – WaldenSchmidt
      Sep 3 at 6:09












    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    You could use perl:



    echo $(( $(printf "%(%s)T") - 5 * 60 )) | perl -lne 'print scalar localtime $_'


    Or in pure perl:



    perl -le 'print scalar localtime(time()-5*60)'


    To format use strftime():



    perl -MPOSIX=strftime -le 'print strftime("%d %h %Y %H:%M:%S", localtime(time()-5*60))'





    share|improve this answer














    You could use perl:



    echo $(( $(printf "%(%s)T") - 5 * 60 )) | perl -lne 'print scalar localtime $_'


    Or in pure perl:



    perl -le 'print scalar localtime(time()-5*60)'


    To format use strftime():



    perl -MPOSIX=strftime -le 'print strftime("%d %h %Y %H:%M:%S", localtime(time()-5*60))'






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 3 at 6:08

























    answered Sep 3 at 5:52









    chaos

    33.9k768112




    33.9k768112











    • The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
      – WaldenSchmidt
      Sep 3 at 6:05











    • @WaldenSchmidt see my edit
      – chaos
      Sep 3 at 6:08










    • Thanks man! This is perfect!
      – WaldenSchmidt
      Sep 3 at 6:09
















    • The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
      – WaldenSchmidt
      Sep 3 at 6:05











    • @WaldenSchmidt see my edit
      – chaos
      Sep 3 at 6:08










    • Thanks man! This is perfect!
      – WaldenSchmidt
      Sep 3 at 6:09















    The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
    – WaldenSchmidt
    Sep 3 at 6:05





    The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
    – WaldenSchmidt
    Sep 3 at 6:05













    @WaldenSchmidt see my edit
    – chaos
    Sep 3 at 6:08




    @WaldenSchmidt see my edit
    – chaos
    Sep 3 at 6:08












    Thanks man! This is perfect!
    – WaldenSchmidt
    Sep 3 at 6:09




    Thanks man! This is perfect!
    – WaldenSchmidt
    Sep 3 at 6:09












    up vote
    5
    down vote













    bash actually copied the %(...)T format from ksh93 but only a small subset.



    That's much more powerful in ksh93.



    $ date; printf '%(%c)Tn' 'exactly five minutes ago'
    Mon 3 Sep 08:08:32 BST 2018
    Mon Sep 3 08:03:32 2018


    bash only supports Unix epoch times (or -1 for now, though with recent versions you can also get now with a missing argument) while ksh93 supports complex relative (including English like above, crontab, at, ISO 8601:2004 durations) or absolute time specifications (see the test data in the source for some examples).



    In ksh93, if you want to pass an epoch time, you use a # prefix:



    $ printf '%(%c)Tn' '#0'
    Thu Jan 1 00:00:00 1970


    (though here, it happens to give the incorrect time for me in a British timezone where epoch time 0 was at 1am)






    share|improve this answer


























      up vote
      5
      down vote













      bash actually copied the %(...)T format from ksh93 but only a small subset.



      That's much more powerful in ksh93.



      $ date; printf '%(%c)Tn' 'exactly five minutes ago'
      Mon 3 Sep 08:08:32 BST 2018
      Mon Sep 3 08:03:32 2018


      bash only supports Unix epoch times (or -1 for now, though with recent versions you can also get now with a missing argument) while ksh93 supports complex relative (including English like above, crontab, at, ISO 8601:2004 durations) or absolute time specifications (see the test data in the source for some examples).



      In ksh93, if you want to pass an epoch time, you use a # prefix:



      $ printf '%(%c)Tn' '#0'
      Thu Jan 1 00:00:00 1970


      (though here, it happens to give the incorrect time for me in a British timezone where epoch time 0 was at 1am)






      share|improve this answer
























        up vote
        5
        down vote










        up vote
        5
        down vote









        bash actually copied the %(...)T format from ksh93 but only a small subset.



        That's much more powerful in ksh93.



        $ date; printf '%(%c)Tn' 'exactly five minutes ago'
        Mon 3 Sep 08:08:32 BST 2018
        Mon Sep 3 08:03:32 2018


        bash only supports Unix epoch times (or -1 for now, though with recent versions you can also get now with a missing argument) while ksh93 supports complex relative (including English like above, crontab, at, ISO 8601:2004 durations) or absolute time specifications (see the test data in the source for some examples).



        In ksh93, if you want to pass an epoch time, you use a # prefix:



        $ printf '%(%c)Tn' '#0'
        Thu Jan 1 00:00:00 1970


        (though here, it happens to give the incorrect time for me in a British timezone where epoch time 0 was at 1am)






        share|improve this answer














        bash actually copied the %(...)T format from ksh93 but only a small subset.



        That's much more powerful in ksh93.



        $ date; printf '%(%c)Tn' 'exactly five minutes ago'
        Mon 3 Sep 08:08:32 BST 2018
        Mon Sep 3 08:03:32 2018


        bash only supports Unix epoch times (or -1 for now, though with recent versions you can also get now with a missing argument) while ksh93 supports complex relative (including English like above, crontab, at, ISO 8601:2004 durations) or absolute time specifications (see the test data in the source for some examples).



        In ksh93, if you want to pass an epoch time, you use a # prefix:



        $ printf '%(%c)Tn' '#0'
        Thu Jan 1 00:00:00 1970


        (though here, it happens to give the incorrect time for me in a British timezone where epoch time 0 was at 1am)







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 3 at 9:47

























        answered Sep 3 at 7:09









        Stéphane Chazelas

        283k53521857




        283k53521857



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466487%2fksh-subtract-5-minutes-from-current-time%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery