subtract 1 hour from date in unix shell script












32















I have the following in a shell script. How can I subtract one hour while retaining the formatting?



DATE=`date "+%m/%d/%Y -%H:%M:%S"`









share|improve this question

































    32















    I have the following in a shell script. How can I subtract one hour while retaining the formatting?



    DATE=`date "+%m/%d/%Y -%H:%M:%S"`









    share|improve this question































      32












      32








      32


      3






      I have the following in a shell script. How can I subtract one hour while retaining the formatting?



      DATE=`date "+%m/%d/%Y -%H:%M:%S"`









      share|improve this question
















      I have the following in a shell script. How can I subtract one hour while retaining the formatting?



      DATE=`date "+%m/%d/%Y -%H:%M:%S"`






      shell datetime unix






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 9 '11 at 20:57









      Karl Bielefeldt

      32.9k44880




      32.9k44880










      asked May 9 '11 at 8:26









      shamir chaikinshamir chaikin

      161139




      161139





























          7 Answers
          7






          active

          oldest

          votes


















          48














          The following command works on recent versions of GNU date:



          date -d '1 hour ago' "+%m/%d/%Y -%H:%M:%S"





          share|improve this answer



















          • 1





            i recieve -date: illegal option -- d usage: date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] date -a [-]sss[.fff]

            – shamir chaikin
            May 9 '11 at 8:40











          • @shamir this means your version of date does not support this option.

            – dogbane
            May 9 '11 at 8:41











          • i figure it out - i post it because may be you know some other way to do it on solaris machine?

            – shamir chaikin
            May 9 '11 at 9:16











          • @shamir, it may be easiest to just install GNU date. You can use a different prefix or path so it doesn't conflict with the "official" one. When I used to do a lot of work on Solaris, I installed a number of GNU utilities in my /home/karl/bin because they have these handy extra options.

            – Karl Bielefeldt
            May 9 '11 at 23:48



















          8














          date -v-60M "+%m/%d/%Y -%H:%M:%S"

          DATE=`date -v-60M "+%m/%d/%Y -%H:%M:%S"`


          If you have bash version 4.4+ you can use bash's internal date printing and arithmetics:



          printf "current date: %(%m/%d/%Y -%H:%M:%S)Tn"
          printf "date - 60min: %(%m/%d/%Y -%H:%M:%S)Tn" $(( $(printf "%(%s)T") - 60 * 60 ))


          The $(printf "%(%s)T") prints the epoch seconds, the $(( epoch - 60*60 )) is bash-aritmetics - subtracting 1hour in seconds. Prints:



          current date: 04/20/2017 -18:14:31
          date - 60min: 04/20/2017 -17:14:31





          share|improve this answer


























          • yes my OS not support it, thanks any way

            – shamir chaikin
            May 11 '11 at 5:30











          • This doesn't work in date shipped on Ubuntu.

            – Flimm
            Jun 15 '16 at 16:10











          • @Flimm This works on OS X and I expect BSD as well

            – Jason S
            Oct 14 '16 at 1:04



















          4














          if you need substract with timestamp :



          timestamp=$(date +%s -d '1 hour ago');





          share|improve this answer































            2














            Convert to timestamp (a long integer), subtract the right number of milliseconds, reformat to the format you need.



            Hard to give more details since you don't specify a programming language...






            share|improve this answer
























            • ahh.. i am using shell script, my formula go like this -DATE=date "+%m/%d/%Y -%H:%M:%S" and from DATE i want to subtract 1 hour

              – shamir chaikin
              May 9 '11 at 8:32






            • 1





              Are you required to stay in shell? An inline awk or perl script could easily subtract an hour and output in your required format.

              – CoreyStup
              May 9 '11 at 20:38



















            1














            This work on my Ubuntu 16.04 date:

            date --date="@$(($(date +%s) - 3600))" "+%m/%d/%Y -%H:%M:%S"

            And the date version is date (GNU coreutils) 8.25






            share|improve this answer































              1














              If you need change timezone before subtraction with new format too:



              $(TZ=US/Eastern date -d '1 hour ago' '+%Y-%m-%d %H:%M')





              share|improve this answer































                0














                Here another way to subtract 1 hour.



                yesterdayDate=`date -d '2018-11-24 00:09 -1 hour' +'%Y-%m-%d %H:%M'` 
                echo $yesterdayDate

                Output:
                2018-11-23 23:09


                I hope that It can help someone.
                Best Regards!






                share|improve this answer























                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  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: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  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
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5934394%2fsubtract-1-hour-from-date-in-unix-shell-script%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  7 Answers
                  7






                  active

                  oldest

                  votes








                  7 Answers
                  7






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  48














                  The following command works on recent versions of GNU date:



                  date -d '1 hour ago' "+%m/%d/%Y -%H:%M:%S"





                  share|improve this answer



















                  • 1





                    i recieve -date: illegal option -- d usage: date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] date -a [-]sss[.fff]

                    – shamir chaikin
                    May 9 '11 at 8:40











                  • @shamir this means your version of date does not support this option.

                    – dogbane
                    May 9 '11 at 8:41











                  • i figure it out - i post it because may be you know some other way to do it on solaris machine?

                    – shamir chaikin
                    May 9 '11 at 9:16











                  • @shamir, it may be easiest to just install GNU date. You can use a different prefix or path so it doesn't conflict with the "official" one. When I used to do a lot of work on Solaris, I installed a number of GNU utilities in my /home/karl/bin because they have these handy extra options.

                    – Karl Bielefeldt
                    May 9 '11 at 23:48
















                  48














                  The following command works on recent versions of GNU date:



                  date -d '1 hour ago' "+%m/%d/%Y -%H:%M:%S"





                  share|improve this answer



















                  • 1





                    i recieve -date: illegal option -- d usage: date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] date -a [-]sss[.fff]

                    – shamir chaikin
                    May 9 '11 at 8:40











                  • @shamir this means your version of date does not support this option.

                    – dogbane
                    May 9 '11 at 8:41











                  • i figure it out - i post it because may be you know some other way to do it on solaris machine?

                    – shamir chaikin
                    May 9 '11 at 9:16











                  • @shamir, it may be easiest to just install GNU date. You can use a different prefix or path so it doesn't conflict with the "official" one. When I used to do a lot of work on Solaris, I installed a number of GNU utilities in my /home/karl/bin because they have these handy extra options.

                    – Karl Bielefeldt
                    May 9 '11 at 23:48














                  48












                  48








                  48







                  The following command works on recent versions of GNU date:



                  date -d '1 hour ago' "+%m/%d/%Y -%H:%M:%S"





                  share|improve this answer













                  The following command works on recent versions of GNU date:



                  date -d '1 hour ago' "+%m/%d/%Y -%H:%M:%S"






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 9 '11 at 8:35









                  dogbanedogbane

                  192k65320374




                  192k65320374








                  • 1





                    i recieve -date: illegal option -- d usage: date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] date -a [-]sss[.fff]

                    – shamir chaikin
                    May 9 '11 at 8:40











                  • @shamir this means your version of date does not support this option.

                    – dogbane
                    May 9 '11 at 8:41











                  • i figure it out - i post it because may be you know some other way to do it on solaris machine?

                    – shamir chaikin
                    May 9 '11 at 9:16











                  • @shamir, it may be easiest to just install GNU date. You can use a different prefix or path so it doesn't conflict with the "official" one. When I used to do a lot of work on Solaris, I installed a number of GNU utilities in my /home/karl/bin because they have these handy extra options.

                    – Karl Bielefeldt
                    May 9 '11 at 23:48














                  • 1





                    i recieve -date: illegal option -- d usage: date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] date -a [-]sss[.fff]

                    – shamir chaikin
                    May 9 '11 at 8:40











                  • @shamir this means your version of date does not support this option.

                    – dogbane
                    May 9 '11 at 8:41











                  • i figure it out - i post it because may be you know some other way to do it on solaris machine?

                    – shamir chaikin
                    May 9 '11 at 9:16











                  • @shamir, it may be easiest to just install GNU date. You can use a different prefix or path so it doesn't conflict with the "official" one. When I used to do a lot of work on Solaris, I installed a number of GNU utilities in my /home/karl/bin because they have these handy extra options.

                    – Karl Bielefeldt
                    May 9 '11 at 23:48








                  1




                  1





                  i recieve -date: illegal option -- d usage: date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] date -a [-]sss[.fff]

                  – shamir chaikin
                  May 9 '11 at 8:40





                  i recieve -date: illegal option -- d usage: date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] date -a [-]sss[.fff]

                  – shamir chaikin
                  May 9 '11 at 8:40













                  @shamir this means your version of date does not support this option.

                  – dogbane
                  May 9 '11 at 8:41





                  @shamir this means your version of date does not support this option.

                  – dogbane
                  May 9 '11 at 8:41













                  i figure it out - i post it because may be you know some other way to do it on solaris machine?

                  – shamir chaikin
                  May 9 '11 at 9:16





                  i figure it out - i post it because may be you know some other way to do it on solaris machine?

                  – shamir chaikin
                  May 9 '11 at 9:16













                  @shamir, it may be easiest to just install GNU date. You can use a different prefix or path so it doesn't conflict with the "official" one. When I used to do a lot of work on Solaris, I installed a number of GNU utilities in my /home/karl/bin because they have these handy extra options.

                  – Karl Bielefeldt
                  May 9 '11 at 23:48





                  @shamir, it may be easiest to just install GNU date. You can use a different prefix or path so it doesn't conflict with the "official" one. When I used to do a lot of work on Solaris, I installed a number of GNU utilities in my /home/karl/bin because they have these handy extra options.

                  – Karl Bielefeldt
                  May 9 '11 at 23:48













                  8














                  date -v-60M "+%m/%d/%Y -%H:%M:%S"

                  DATE=`date -v-60M "+%m/%d/%Y -%H:%M:%S"`


                  If you have bash version 4.4+ you can use bash's internal date printing and arithmetics:



                  printf "current date: %(%m/%d/%Y -%H:%M:%S)Tn"
                  printf "date - 60min: %(%m/%d/%Y -%H:%M:%S)Tn" $(( $(printf "%(%s)T") - 60 * 60 ))


                  The $(printf "%(%s)T") prints the epoch seconds, the $(( epoch - 60*60 )) is bash-aritmetics - subtracting 1hour in seconds. Prints:



                  current date: 04/20/2017 -18:14:31
                  date - 60min: 04/20/2017 -17:14:31





                  share|improve this answer


























                  • yes my OS not support it, thanks any way

                    – shamir chaikin
                    May 11 '11 at 5:30











                  • This doesn't work in date shipped on Ubuntu.

                    – Flimm
                    Jun 15 '16 at 16:10











                  • @Flimm This works on OS X and I expect BSD as well

                    – Jason S
                    Oct 14 '16 at 1:04
















                  8














                  date -v-60M "+%m/%d/%Y -%H:%M:%S"

                  DATE=`date -v-60M "+%m/%d/%Y -%H:%M:%S"`


                  If you have bash version 4.4+ you can use bash's internal date printing and arithmetics:



                  printf "current date: %(%m/%d/%Y -%H:%M:%S)Tn"
                  printf "date - 60min: %(%m/%d/%Y -%H:%M:%S)Tn" $(( $(printf "%(%s)T") - 60 * 60 ))


                  The $(printf "%(%s)T") prints the epoch seconds, the $(( epoch - 60*60 )) is bash-aritmetics - subtracting 1hour in seconds. Prints:



                  current date: 04/20/2017 -18:14:31
                  date - 60min: 04/20/2017 -17:14:31





                  share|improve this answer


























                  • yes my OS not support it, thanks any way

                    – shamir chaikin
                    May 11 '11 at 5:30











                  • This doesn't work in date shipped on Ubuntu.

                    – Flimm
                    Jun 15 '16 at 16:10











                  • @Flimm This works on OS X and I expect BSD as well

                    – Jason S
                    Oct 14 '16 at 1:04














                  8












                  8








                  8







                  date -v-60M "+%m/%d/%Y -%H:%M:%S"

                  DATE=`date -v-60M "+%m/%d/%Y -%H:%M:%S"`


                  If you have bash version 4.4+ you can use bash's internal date printing and arithmetics:



                  printf "current date: %(%m/%d/%Y -%H:%M:%S)Tn"
                  printf "date - 60min: %(%m/%d/%Y -%H:%M:%S)Tn" $(( $(printf "%(%s)T") - 60 * 60 ))


                  The $(printf "%(%s)T") prints the epoch seconds, the $(( epoch - 60*60 )) is bash-aritmetics - subtracting 1hour in seconds. Prints:



                  current date: 04/20/2017 -18:14:31
                  date - 60min: 04/20/2017 -17:14:31





                  share|improve this answer















                  date -v-60M "+%m/%d/%Y -%H:%M:%S"

                  DATE=`date -v-60M "+%m/%d/%Y -%H:%M:%S"`


                  If you have bash version 4.4+ you can use bash's internal date printing and arithmetics:



                  printf "current date: %(%m/%d/%Y -%H:%M:%S)Tn"
                  printf "date - 60min: %(%m/%d/%Y -%H:%M:%S)Tn" $(( $(printf "%(%s)T") - 60 * 60 ))


                  The $(printf "%(%s)T") prints the epoch seconds, the $(( epoch - 60*60 )) is bash-aritmetics - subtracting 1hour in seconds. Prints:



                  current date: 04/20/2017 -18:14:31
                  date - 60min: 04/20/2017 -17:14:31






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 20 '17 at 16:18

























                  answered May 9 '11 at 21:11









                  jm666jm666

                  43.6k1175144




                  43.6k1175144













                  • yes my OS not support it, thanks any way

                    – shamir chaikin
                    May 11 '11 at 5:30











                  • This doesn't work in date shipped on Ubuntu.

                    – Flimm
                    Jun 15 '16 at 16:10











                  • @Flimm This works on OS X and I expect BSD as well

                    – Jason S
                    Oct 14 '16 at 1:04



















                  • yes my OS not support it, thanks any way

                    – shamir chaikin
                    May 11 '11 at 5:30











                  • This doesn't work in date shipped on Ubuntu.

                    – Flimm
                    Jun 15 '16 at 16:10











                  • @Flimm This works on OS X and I expect BSD as well

                    – Jason S
                    Oct 14 '16 at 1:04

















                  yes my OS not support it, thanks any way

                  – shamir chaikin
                  May 11 '11 at 5:30





                  yes my OS not support it, thanks any way

                  – shamir chaikin
                  May 11 '11 at 5:30













                  This doesn't work in date shipped on Ubuntu.

                  – Flimm
                  Jun 15 '16 at 16:10





                  This doesn't work in date shipped on Ubuntu.

                  – Flimm
                  Jun 15 '16 at 16:10













                  @Flimm This works on OS X and I expect BSD as well

                  – Jason S
                  Oct 14 '16 at 1:04





                  @Flimm This works on OS X and I expect BSD as well

                  – Jason S
                  Oct 14 '16 at 1:04











                  4














                  if you need substract with timestamp :



                  timestamp=$(date +%s -d '1 hour ago');





                  share|improve this answer




























                    4














                    if you need substract with timestamp :



                    timestamp=$(date +%s -d '1 hour ago');





                    share|improve this answer


























                      4












                      4








                      4







                      if you need substract with timestamp :



                      timestamp=$(date +%s -d '1 hour ago');





                      share|improve this answer













                      if you need substract with timestamp :



                      timestamp=$(date +%s -d '1 hour ago');






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Dec 4 '15 at 15:15









                      leGabianleGabian

                      412




                      412























                          2














                          Convert to timestamp (a long integer), subtract the right number of milliseconds, reformat to the format you need.



                          Hard to give more details since you don't specify a programming language...






                          share|improve this answer
























                          • ahh.. i am using shell script, my formula go like this -DATE=date "+%m/%d/%Y -%H:%M:%S" and from DATE i want to subtract 1 hour

                            – shamir chaikin
                            May 9 '11 at 8:32






                          • 1





                            Are you required to stay in shell? An inline awk or perl script could easily subtract an hour and output in your required format.

                            – CoreyStup
                            May 9 '11 at 20:38
















                          2














                          Convert to timestamp (a long integer), subtract the right number of milliseconds, reformat to the format you need.



                          Hard to give more details since you don't specify a programming language...






                          share|improve this answer
























                          • ahh.. i am using shell script, my formula go like this -DATE=date "+%m/%d/%Y -%H:%M:%S" and from DATE i want to subtract 1 hour

                            – shamir chaikin
                            May 9 '11 at 8:32






                          • 1





                            Are you required to stay in shell? An inline awk or perl script could easily subtract an hour and output in your required format.

                            – CoreyStup
                            May 9 '11 at 20:38














                          2












                          2








                          2







                          Convert to timestamp (a long integer), subtract the right number of milliseconds, reformat to the format you need.



                          Hard to give more details since you don't specify a programming language...






                          share|improve this answer













                          Convert to timestamp (a long integer), subtract the right number of milliseconds, reformat to the format you need.



                          Hard to give more details since you don't specify a programming language...







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered May 9 '11 at 8:29









                          PhiLhoPhiLho

                          35.1k379122




                          35.1k379122













                          • ahh.. i am using shell script, my formula go like this -DATE=date "+%m/%d/%Y -%H:%M:%S" and from DATE i want to subtract 1 hour

                            – shamir chaikin
                            May 9 '11 at 8:32






                          • 1





                            Are you required to stay in shell? An inline awk or perl script could easily subtract an hour and output in your required format.

                            – CoreyStup
                            May 9 '11 at 20:38



















                          • ahh.. i am using shell script, my formula go like this -DATE=date "+%m/%d/%Y -%H:%M:%S" and from DATE i want to subtract 1 hour

                            – shamir chaikin
                            May 9 '11 at 8:32






                          • 1





                            Are you required to stay in shell? An inline awk or perl script could easily subtract an hour and output in your required format.

                            – CoreyStup
                            May 9 '11 at 20:38

















                          ahh.. i am using shell script, my formula go like this -DATE=date "+%m/%d/%Y -%H:%M:%S" and from DATE i want to subtract 1 hour

                          – shamir chaikin
                          May 9 '11 at 8:32





                          ahh.. i am using shell script, my formula go like this -DATE=date "+%m/%d/%Y -%H:%M:%S" and from DATE i want to subtract 1 hour

                          – shamir chaikin
                          May 9 '11 at 8:32




                          1




                          1





                          Are you required to stay in shell? An inline awk or perl script could easily subtract an hour and output in your required format.

                          – CoreyStup
                          May 9 '11 at 20:38





                          Are you required to stay in shell? An inline awk or perl script could easily subtract an hour and output in your required format.

                          – CoreyStup
                          May 9 '11 at 20:38











                          1














                          This work on my Ubuntu 16.04 date:

                          date --date="@$(($(date +%s) - 3600))" "+%m/%d/%Y -%H:%M:%S"

                          And the date version is date (GNU coreutils) 8.25






                          share|improve this answer




























                            1














                            This work on my Ubuntu 16.04 date:

                            date --date="@$(($(date +%s) - 3600))" "+%m/%d/%Y -%H:%M:%S"

                            And the date version is date (GNU coreutils) 8.25






                            share|improve this answer


























                              1












                              1








                              1







                              This work on my Ubuntu 16.04 date:

                              date --date="@$(($(date +%s) - 3600))" "+%m/%d/%Y -%H:%M:%S"

                              And the date version is date (GNU coreutils) 8.25






                              share|improve this answer













                              This work on my Ubuntu 16.04 date:

                              date --date="@$(($(date +%s) - 3600))" "+%m/%d/%Y -%H:%M:%S"

                              And the date version is date (GNU coreutils) 8.25







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Mar 21 '17 at 12:14









                              ray_gray_g

                              265




                              265























                                  1














                                  If you need change timezone before subtraction with new format too:



                                  $(TZ=US/Eastern date -d '1 hour ago' '+%Y-%m-%d %H:%M')





                                  share|improve this answer




























                                    1














                                    If you need change timezone before subtraction with new format too:



                                    $(TZ=US/Eastern date -d '1 hour ago' '+%Y-%m-%d %H:%M')





                                    share|improve this answer


























                                      1












                                      1








                                      1







                                      If you need change timezone before subtraction with new format too:



                                      $(TZ=US/Eastern date -d '1 hour ago' '+%Y-%m-%d %H:%M')





                                      share|improve this answer













                                      If you need change timezone before subtraction with new format too:



                                      $(TZ=US/Eastern date -d '1 hour ago' '+%Y-%m-%d %H:%M')






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered May 24 '18 at 10:37









                                      Kenan DumanKenan Duman

                                      544




                                      544























                                          0














                                          Here another way to subtract 1 hour.



                                          yesterdayDate=`date -d '2018-11-24 00:09 -1 hour' +'%Y-%m-%d %H:%M'` 
                                          echo $yesterdayDate

                                          Output:
                                          2018-11-23 23:09


                                          I hope that It can help someone.
                                          Best Regards!






                                          share|improve this answer




























                                            0














                                            Here another way to subtract 1 hour.



                                            yesterdayDate=`date -d '2018-11-24 00:09 -1 hour' +'%Y-%m-%d %H:%M'` 
                                            echo $yesterdayDate

                                            Output:
                                            2018-11-23 23:09


                                            I hope that It can help someone.
                                            Best Regards!






                                            share|improve this answer


























                                              0












                                              0








                                              0







                                              Here another way to subtract 1 hour.



                                              yesterdayDate=`date -d '2018-11-24 00:09 -1 hour' +'%Y-%m-%d %H:%M'` 
                                              echo $yesterdayDate

                                              Output:
                                              2018-11-23 23:09


                                              I hope that It can help someone.
                                              Best Regards!






                                              share|improve this answer













                                              Here another way to subtract 1 hour.



                                              yesterdayDate=`date -d '2018-11-24 00:09 -1 hour' +'%Y-%m-%d %H:%M'` 
                                              echo $yesterdayDate

                                              Output:
                                              2018-11-23 23:09


                                              I hope that It can help someone.
                                              Best Regards!







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Nov 24 '18 at 21:29









                                              Javier MuñozJavier Muñoz

                                              3311518




                                              3311518






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • 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%2fstackoverflow.com%2fquestions%2f5934394%2fsubtract-1-hour-from-date-in-unix-shell-script%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

                                                  Create new schema in PostgreSQL using DBeaver

                                                  Deepest pit of an array with Javascript: test on Codility

                                                  Fotorealismo