Convert Date string in timestampBash : compare two strings with spaceLeap seconds and dateIssues with storing...

What is the fastest way to level past 95 in Diablo II?

What should we do with manuals from the 80s?

Will some rockets really collapse under their own weight?

Duplicate and slide edge (rip from boundary)

Understanding a part of the proof that sequence that converges to square root of two is decreasing.

Meaning of だけはわからない

Is this bar slide trick shown on Cheers real or a visual effect?

When did Bilbo and Frodo learn that Gandalf was a Maia?

Can anyone help me what's wrong here as i can prove 0 = 1?

When does The Truman Show take place?

Why does Japan use the same type of AC power outlet as the US?

Does writing regular diary entries count as writing practice?

Why is the battery jumpered to a resistor in this schematic?

Can I use my OWN published papers' images in my thesis without Copyright infringment

May the tower use the runway while an emergency aircraft is inbound?

Is there a word for returning to unpreparedness?

Adding things to bunches of things vs multiplication

Why does "auf der Strecke bleiben" mean "to fall by the wayside"?

What is the opposite of "hunger level"?

Did Michelle Obama have a staff of 23; and Melania have a staff of 4?

What are these panels underneath the wing root of a A380?

Good way to stop electrolyte tabs from turning into powder?

How would armour (and combat) change if the fighter didn't need to actually wear it?

Is Fourier series a sampled version of Fourier transform?



Convert Date string in timestamp


Bash : compare two strings with spaceLeap seconds and dateIssues with storing an echo of a date conversion into a string variable inunixScript using user input to calculate old datePopulate array with a sed/echo combinationHow to convert date to timestampConvert string dateHow can I calculate and format a date duration using GNU tools, not a result date?Bash command to rename files and convert datestamp from 'dd[st/nd/rd/th] mmm yyyy' to 'yyyymmdd'?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I can't find the right syntax to convert a string date in epoch timestamp.



The script is:



date -d '2012-03-02 22:00 EDT' +%s
DATEJ=`echo -n '2012-03-02 22:00'`
echo $DATEJ
date -d $DATEJ EDT +%s


and the result is



[gg@raspi8 ~]$ CNVDATTS
1330740000
'2012-03-02 22:00'
date: opérande supplémentaire « EDT »
Saisissez « date --help » pour plus d'informations.


Where is the fault?



It seems that the variable DATEJ does not give the same as the string in the 1st line. If I don't write EDT, the error is same but mention +%s.










share|improve this question









New contributor



Georges Guinchard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






















  • What type of Unix are you running on?

    – Kusalananda
    yesterday






  • 1





    what's the point of the echo -n? why not just DATEJ='2012-03-02 22:00'? Also, you need double-quotes when you use $DATEJ - e.g. date -d "$DATEJ EDT" +%s, otherwise date will get three arguments $DATEJ, EDT, and +%s instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :)

    – cas
    yesterday


















0















I can't find the right syntax to convert a string date in epoch timestamp.



The script is:



date -d '2012-03-02 22:00 EDT' +%s
DATEJ=`echo -n '2012-03-02 22:00'`
echo $DATEJ
date -d $DATEJ EDT +%s


and the result is



[gg@raspi8 ~]$ CNVDATTS
1330740000
'2012-03-02 22:00'
date: opérande supplémentaire « EDT »
Saisissez « date --help » pour plus d'informations.


Where is the fault?



It seems that the variable DATEJ does not give the same as the string in the 1st line. If I don't write EDT, the error is same but mention +%s.










share|improve this question









New contributor



Georges Guinchard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






















  • What type of Unix are you running on?

    – Kusalananda
    yesterday






  • 1





    what's the point of the echo -n? why not just DATEJ='2012-03-02 22:00'? Also, you need double-quotes when you use $DATEJ - e.g. date -d "$DATEJ EDT" +%s, otherwise date will get three arguments $DATEJ, EDT, and +%s instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :)

    – cas
    yesterday














0












0








0








I can't find the right syntax to convert a string date in epoch timestamp.



The script is:



date -d '2012-03-02 22:00 EDT' +%s
DATEJ=`echo -n '2012-03-02 22:00'`
echo $DATEJ
date -d $DATEJ EDT +%s


and the result is



[gg@raspi8 ~]$ CNVDATTS
1330740000
'2012-03-02 22:00'
date: opérande supplémentaire « EDT »
Saisissez « date --help » pour plus d'informations.


Where is the fault?



It seems that the variable DATEJ does not give the same as the string in the 1st line. If I don't write EDT, the error is same but mention +%s.










share|improve this question









New contributor



Georges Guinchard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I can't find the right syntax to convert a string date in epoch timestamp.



The script is:



date -d '2012-03-02 22:00 EDT' +%s
DATEJ=`echo -n '2012-03-02 22:00'`
echo $DATEJ
date -d $DATEJ EDT +%s


and the result is



[gg@raspi8 ~]$ CNVDATTS
1330740000
'2012-03-02 22:00'
date: opérande supplémentaire « EDT »
Saisissez « date --help » pour plus d'informations.


Where is the fault?



It seems that the variable DATEJ does not give the same as the string in the 1st line. If I don't write EDT, the error is same but mention +%s.







bash date syntax






share|improve this question









New contributor



Georges Guinchard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



Georges Guinchard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question








edited yesterday









Bart

1,2041 gold badge3 silver badges18 bronze badges




1,2041 gold badge3 silver badges18 bronze badges






New contributor



Georges Guinchard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked yesterday









Georges GuinchardGeorges Guinchard

4




4




New contributor



Georges Guinchard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




Georges Guinchard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • What type of Unix are you running on?

    – Kusalananda
    yesterday






  • 1





    what's the point of the echo -n? why not just DATEJ='2012-03-02 22:00'? Also, you need double-quotes when you use $DATEJ - e.g. date -d "$DATEJ EDT" +%s, otherwise date will get three arguments $DATEJ, EDT, and +%s instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :)

    – cas
    yesterday



















  • What type of Unix are you running on?

    – Kusalananda
    yesterday






  • 1





    what's the point of the echo -n? why not just DATEJ='2012-03-02 22:00'? Also, you need double-quotes when you use $DATEJ - e.g. date -d "$DATEJ EDT" +%s, otherwise date will get three arguments $DATEJ, EDT, and +%s instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :)

    – cas
    yesterday

















What type of Unix are you running on?

– Kusalananda
yesterday





What type of Unix are you running on?

– Kusalananda
yesterday




1




1





what's the point of the echo -n? why not just DATEJ='2012-03-02 22:00'? Also, you need double-quotes when you use $DATEJ - e.g. date -d "$DATEJ EDT" +%s, otherwise date will get three arguments $DATEJ, EDT, and +%s instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :)

– cas
yesterday





what's the point of the echo -n? why not just DATEJ='2012-03-02 22:00'? Also, you need double-quotes when you use $DATEJ - e.g. date -d "$DATEJ EDT" +%s, otherwise date will get three arguments $DATEJ, EDT, and +%s instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :)

– cas
yesterday










1 Answer
1






active

oldest

votes


















1














The problem here seems to be with the single-quotes in $DATEJ. Your variable imposes them.



Change that to



DATEJ=`echo -n "2012-03-02 22:00"`


and in the final command:



date -d "$DATEJ EDT" +%s


This will work:



$ date -d '2012-03-02 22:00 EDT' +%s
1330740000
$ DATEJ=`echo -n "2012-03-02 22:00"`
$ echo $DATEJ
2012-03-02 22:00
$ date -d "$DATEJ EDT" +%s
1330740000


EDIT



Actually, you don't need to echo the date, unless your script imposes so, so the variable $DATEJ can simply be put as



DATEJ="2012-03-02 22:00"





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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Georges Guinchard is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f535714%2fconvert-date-string-in-timestamp%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The problem here seems to be with the single-quotes in $DATEJ. Your variable imposes them.



    Change that to



    DATEJ=`echo -n "2012-03-02 22:00"`


    and in the final command:



    date -d "$DATEJ EDT" +%s


    This will work:



    $ date -d '2012-03-02 22:00 EDT' +%s
    1330740000
    $ DATEJ=`echo -n "2012-03-02 22:00"`
    $ echo $DATEJ
    2012-03-02 22:00
    $ date -d "$DATEJ EDT" +%s
    1330740000


    EDIT



    Actually, you don't need to echo the date, unless your script imposes so, so the variable $DATEJ can simply be put as



    DATEJ="2012-03-02 22:00"





    share|improve this answer






























      1














      The problem here seems to be with the single-quotes in $DATEJ. Your variable imposes them.



      Change that to



      DATEJ=`echo -n "2012-03-02 22:00"`


      and in the final command:



      date -d "$DATEJ EDT" +%s


      This will work:



      $ date -d '2012-03-02 22:00 EDT' +%s
      1330740000
      $ DATEJ=`echo -n "2012-03-02 22:00"`
      $ echo $DATEJ
      2012-03-02 22:00
      $ date -d "$DATEJ EDT" +%s
      1330740000


      EDIT



      Actually, you don't need to echo the date, unless your script imposes so, so the variable $DATEJ can simply be put as



      DATEJ="2012-03-02 22:00"





      share|improve this answer




























        1












        1








        1







        The problem here seems to be with the single-quotes in $DATEJ. Your variable imposes them.



        Change that to



        DATEJ=`echo -n "2012-03-02 22:00"`


        and in the final command:



        date -d "$DATEJ EDT" +%s


        This will work:



        $ date -d '2012-03-02 22:00 EDT' +%s
        1330740000
        $ DATEJ=`echo -n "2012-03-02 22:00"`
        $ echo $DATEJ
        2012-03-02 22:00
        $ date -d "$DATEJ EDT" +%s
        1330740000


        EDIT



        Actually, you don't need to echo the date, unless your script imposes so, so the variable $DATEJ can simply be put as



        DATEJ="2012-03-02 22:00"





        share|improve this answer













        The problem here seems to be with the single-quotes in $DATEJ. Your variable imposes them.



        Change that to



        DATEJ=`echo -n "2012-03-02 22:00"`


        and in the final command:



        date -d "$DATEJ EDT" +%s


        This will work:



        $ date -d '2012-03-02 22:00 EDT' +%s
        1330740000
        $ DATEJ=`echo -n "2012-03-02 22:00"`
        $ echo $DATEJ
        2012-03-02 22:00
        $ date -d "$DATEJ EDT" +%s
        1330740000


        EDIT



        Actually, you don't need to echo the date, unless your script imposes so, so the variable $DATEJ can simply be put as



        DATEJ="2012-03-02 22:00"






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        BartBart

        1,2041 gold badge3 silver badges18 bronze badges




        1,2041 gold badge3 silver badges18 bronze badges

























            Georges Guinchard is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            Georges Guinchard is a new contributor. Be nice, and check out our Code of Conduct.













            Georges Guinchard is a new contributor. Be nice, and check out our Code of Conduct.












            Georges Guinchard is a new contributor. Be nice, and check out our Code of Conduct.
















            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f535714%2fconvert-date-string-in-timestamp%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...