Get date of Monday two weeks ago from particular date using GNU date2019 Community Moderator ElectionSolaris: find the day of last Monday,Tuesday,…Sunday by means of shell scriptLinux date/time - monthly “mongodump”date command, going back one or two days. Seeing different flagscalendar to check the date and then search 3 months back and add up the days of those monthsHow do I get the date from two weeks ago using Solaris' date?Script to compare job date to today's date and only output today's failuresBash format returns zeroes for H MHow to output a date/time as “20 minutes ago” or “9 days ago”, etcPick off 'first' dates using cal function in bashFind the difference between 2 dates

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

Which Article Helped Get Rid of Technobabble in RPGs?

Creating two special characters

How do I fix the group tension caused by my character stealing and possibly killing without provocation?

What (the heck) is a Super Worm Equinox Moon?

How can I write humor as character trait?

awk assign to multiple variables at once

How to make money from a browser who sees 5 seconds into the future of any web page?

Giving feedback to someone without sounding prejudiced

What fields between the rationals and the reals allow a good notion of 2D distance?

How do I tell my boss that I'm quitting soon, especially given that a colleague just left this week

Why is the "ls" command showing permissions of files in a FAT32 partition?

Doesn't the system of the Supreme Court oppose justice?

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?

Why should universal income be universal?

Is there a nicer/politer/more positive alternative for "negates"?

Does the reader need to like the PoV character?

Strong empirical falsification of quantum mechanics based on vacuum energy density?

The Digit Triangles

What is the difference between lands and mana?

Why do ¬, ∀ and ∃ have the same precedence?

Does "he squandered his car on drink" sound natural?

How much theory knowledge is actually used while playing?

Why does the Sun have different day lengths, but not the gas giants?



Get date of Monday two weeks ago from particular date using GNU date



2019 Community Moderator ElectionSolaris: find the day of last Monday,Tuesday,…Sunday by means of shell scriptLinux date/time - monthly “mongodump”date command, going back one or two days. Seeing different flagscalendar to check the date and then search 3 months back and add up the days of those monthsHow do I get the date from two weeks ago using Solaris' date?Script to compare job date to today's date and only output today's failuresBash format returns zeroes for H MHow to output a date/time as “20 minutes ago” or “9 days ago”, etcPick off 'first' dates using cal function in bashFind the difference between 2 dates










0















I understand the command date -d 'last-monday - 14 days' +%Y%m%d will print the Monday two weeks ago from "Today's date". I need a way to test this for different dates and see the result. Almost like I need to mention the date command to do calculations off a relative date.



I need something to test with different dateslike :



date -d 'last-monday - 14 days' %Y%m%d from 20190315

date -d 'last-monday - 14 days' %Y%m%d from 20180217

date -d 'last-monday - 14 days' %Y%m%d from 201700914


and see the respective outputs.










share|improve this question









New contributor




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




















  • You'd want a way to get (respectively to your example) results such as: 20190225 and 20180129 and 20170828, am I correct ?

    – LL3
    yesterday















0















I understand the command date -d 'last-monday - 14 days' +%Y%m%d will print the Monday two weeks ago from "Today's date". I need a way to test this for different dates and see the result. Almost like I need to mention the date command to do calculations off a relative date.



I need something to test with different dateslike :



date -d 'last-monday - 14 days' %Y%m%d from 20190315

date -d 'last-monday - 14 days' %Y%m%d from 20180217

date -d 'last-monday - 14 days' %Y%m%d from 201700914


and see the respective outputs.










share|improve this question









New contributor




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




















  • You'd want a way to get (respectively to your example) results such as: 20190225 and 20180129 and 20170828, am I correct ?

    – LL3
    yesterday













0












0








0








I understand the command date -d 'last-monday - 14 days' +%Y%m%d will print the Monday two weeks ago from "Today's date". I need a way to test this for different dates and see the result. Almost like I need to mention the date command to do calculations off a relative date.



I need something to test with different dateslike :



date -d 'last-monday - 14 days' %Y%m%d from 20190315

date -d 'last-monday - 14 days' %Y%m%d from 20180217

date -d 'last-monday - 14 days' %Y%m%d from 201700914


and see the respective outputs.










share|improve this question









New contributor




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












I understand the command date -d 'last-monday - 14 days' +%Y%m%d will print the Monday two weeks ago from "Today's date". I need a way to test this for different dates and see the result. Almost like I need to mention the date command to do calculations off a relative date.



I need something to test with different dateslike :



date -d 'last-monday - 14 days' %Y%m%d from 20190315

date -d 'last-monday - 14 days' %Y%m%d from 20180217

date -d 'last-monday - 14 days' %Y%m%d from 201700914


and see the respective outputs.







linux date






share|improve this question









New contributor




Eternal Learner 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




Eternal Learner 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









Kusalananda

137k17258426




137k17258426






New contributor




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









asked yesterday









Eternal LearnerEternal Learner

1032




1032




New contributor




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





New contributor





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






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












  • You'd want a way to get (respectively to your example) results such as: 20190225 and 20180129 and 20170828, am I correct ?

    – LL3
    yesterday

















  • You'd want a way to get (respectively to your example) results such as: 20190225 and 20180129 and 20170828, am I correct ?

    – LL3
    yesterday
















You'd want a way to get (respectively to your example) results such as: 20190225 and 20180129 and 20170828, am I correct ?

– LL3
yesterday





You'd want a way to get (respectively to your example) results such as: 20190225 and 20180129 and 20170828, am I correct ?

– LL3
yesterday










5 Answers
5






active

oldest

votes


















1














#!/bin/bash

# Our given dates
dates=(
20190315
20180217
20170914
)

# Loop over the given dates
for thedate in "$dates[@]"; do
# Get day of the week as digit (1 is Monday, 7 is Sunday)
day=$( date -d "$thedate" +%u )
# The Monday the same week is $(( day - 1 )) days earlier than the given date.
# The Monday two weeks earlier is 14 days earlier still.

date -d "$thedate -$(( day - 1 + 14 )) days" +"$thedate --> %Y%m%d"
done


Output:



20190315 --> 20190225
20180217 --> 20180129
20170914 --> 20170828


The difficult bit about this is to figure out how to construct the correct --date or -d string for GNU date to compute the final date. I opted for computing the day of week of the given date, and then using that to compute a date string that offsets the given date by a number of days so that the resulting date is the Monday two weeks earlier.



The actual strings that ends up being used for the option argument to -d in the above script, using the dates given in the script, are



20190315 -18 days
20180217 -19 days
20170914 -17 days


Condensing the script into a single command that does the computation for a single date in $thedate:



date -d "$thedate -$(date -d "$thedate" +%u) days -13 days" +%Y%m%d


or



date -d "$thedate -$(date -d "$thedate" +"-%u days -13 days")" +%Y%m%d





share|improve this answer

























  • Thank you. This works great.

    – Eternal Learner
    12 hours ago


















3














On at least Debian there is a faketime package



faketime '2019-03-15' date
Fri 15 Mar 00:00:00 GMT 2019

faketime '2019-03-15' date --date 'last monday - 14 days'
Mon 25 Feb 00:00:00 GMT 2019





share|improve this answer






























    2














    $ date
    Wed Mar 20 15:02:23 MST 2019
    $ date -d "last-monday"
    Mon Mar 18 00:00:00 MST 2019
    $ date -d "last-monday - 1 week"
    Mon Mar 11 00:00:00 MST 2019





    share|improve this answer


















    • 2





      The issue seems to be finding the date of the Monday two weeks before a particular date.

      – Kusalananda
      yesterday


















    0














    The overkill solution:



    Create a bare-bones virtual machine. 
    Run it in single user mode,
    so no background services are running. 
    Just to be sure, double-check that NTP is not running.



    Then set the date to whatever you want to set it to,
    and do your tests.






    share|improve this answer






























      -1














      Use the date command's -s/--set option:



      # date
      Wed Mar 20 23:02:18 CET 2019
      # date -s '20190315' > /dev/null; date -d 'last-monday - 14 days'
      Mon Feb 25 00:00:00 CET 2019


      Depending on your system, you might have to prefix with sudo or reset afterwards via ntpdate






      share|improve this answer








      New contributor




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















      • 1





        Setting the system's clock seems like overkill just to get the correct output. It may also confuse certain services and scheduled tasks, and other users of the system if it's a multi-user system.

        – Kusalananda
        yesterday












      • @Kusalananda I agree, in principle, but most modern systems will automatically resync via ntp anyway. When I tested this, date returned the correct time immediately afterwards; hence the ; instead of using two separate commands to show what I'm doing. But if you really don't want to touch your system time, there does exist a faketime package.

        – Entropy0
        yesterday











      • The ntpd daemon won't resync if you exceed its the 300 second variance.

        – roaima
        yesterday











      • Then there is something else going on in my system (Mint 19), because 5d > 300s and as I said: running above command didn't affect anything beyond the commands in the current line. In fact: # date -s '19700102' ; date ; sleep 1 ; date yields Fri Jan 2 00:00:00 CET 1970 Fri Jan 2 00:00:00 CET 1970 Wed Mar 20 23:49:26 CET 2019

        – Entropy0
        yesterday












      • Maybe you're running ntpdate from cron (ugh), or perhaps chrony has a larger leeway. Or there again there's whatever the systemd borg has done to NTP.

        – roaima
        yesterday











      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
      );



      );






      Eternal Learner 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%2f507549%2fget-date-of-monday-two-weeks-ago-from-particular-date-using-gnu-date%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      #!/bin/bash

      # Our given dates
      dates=(
      20190315
      20180217
      20170914
      )

      # Loop over the given dates
      for thedate in "$dates[@]"; do
      # Get day of the week as digit (1 is Monday, 7 is Sunday)
      day=$( date -d "$thedate" +%u )
      # The Monday the same week is $(( day - 1 )) days earlier than the given date.
      # The Monday two weeks earlier is 14 days earlier still.

      date -d "$thedate -$(( day - 1 + 14 )) days" +"$thedate --> %Y%m%d"
      done


      Output:



      20190315 --> 20190225
      20180217 --> 20180129
      20170914 --> 20170828


      The difficult bit about this is to figure out how to construct the correct --date or -d string for GNU date to compute the final date. I opted for computing the day of week of the given date, and then using that to compute a date string that offsets the given date by a number of days so that the resulting date is the Monday two weeks earlier.



      The actual strings that ends up being used for the option argument to -d in the above script, using the dates given in the script, are



      20190315 -18 days
      20180217 -19 days
      20170914 -17 days


      Condensing the script into a single command that does the computation for a single date in $thedate:



      date -d "$thedate -$(date -d "$thedate" +%u) days -13 days" +%Y%m%d


      or



      date -d "$thedate -$(date -d "$thedate" +"-%u days -13 days")" +%Y%m%d





      share|improve this answer

























      • Thank you. This works great.

        – Eternal Learner
        12 hours ago















      1














      #!/bin/bash

      # Our given dates
      dates=(
      20190315
      20180217
      20170914
      )

      # Loop over the given dates
      for thedate in "$dates[@]"; do
      # Get day of the week as digit (1 is Monday, 7 is Sunday)
      day=$( date -d "$thedate" +%u )
      # The Monday the same week is $(( day - 1 )) days earlier than the given date.
      # The Monday two weeks earlier is 14 days earlier still.

      date -d "$thedate -$(( day - 1 + 14 )) days" +"$thedate --> %Y%m%d"
      done


      Output:



      20190315 --> 20190225
      20180217 --> 20180129
      20170914 --> 20170828


      The difficult bit about this is to figure out how to construct the correct --date or -d string for GNU date to compute the final date. I opted for computing the day of week of the given date, and then using that to compute a date string that offsets the given date by a number of days so that the resulting date is the Monday two weeks earlier.



      The actual strings that ends up being used for the option argument to -d in the above script, using the dates given in the script, are



      20190315 -18 days
      20180217 -19 days
      20170914 -17 days


      Condensing the script into a single command that does the computation for a single date in $thedate:



      date -d "$thedate -$(date -d "$thedate" +%u) days -13 days" +%Y%m%d


      or



      date -d "$thedate -$(date -d "$thedate" +"-%u days -13 days")" +%Y%m%d





      share|improve this answer

























      • Thank you. This works great.

        – Eternal Learner
        12 hours ago













      1












      1








      1







      #!/bin/bash

      # Our given dates
      dates=(
      20190315
      20180217
      20170914
      )

      # Loop over the given dates
      for thedate in "$dates[@]"; do
      # Get day of the week as digit (1 is Monday, 7 is Sunday)
      day=$( date -d "$thedate" +%u )
      # The Monday the same week is $(( day - 1 )) days earlier than the given date.
      # The Monday two weeks earlier is 14 days earlier still.

      date -d "$thedate -$(( day - 1 + 14 )) days" +"$thedate --> %Y%m%d"
      done


      Output:



      20190315 --> 20190225
      20180217 --> 20180129
      20170914 --> 20170828


      The difficult bit about this is to figure out how to construct the correct --date or -d string for GNU date to compute the final date. I opted for computing the day of week of the given date, and then using that to compute a date string that offsets the given date by a number of days so that the resulting date is the Monday two weeks earlier.



      The actual strings that ends up being used for the option argument to -d in the above script, using the dates given in the script, are



      20190315 -18 days
      20180217 -19 days
      20170914 -17 days


      Condensing the script into a single command that does the computation for a single date in $thedate:



      date -d "$thedate -$(date -d "$thedate" +%u) days -13 days" +%Y%m%d


      or



      date -d "$thedate -$(date -d "$thedate" +"-%u days -13 days")" +%Y%m%d





      share|improve this answer















      #!/bin/bash

      # Our given dates
      dates=(
      20190315
      20180217
      20170914
      )

      # Loop over the given dates
      for thedate in "$dates[@]"; do
      # Get day of the week as digit (1 is Monday, 7 is Sunday)
      day=$( date -d "$thedate" +%u )
      # The Monday the same week is $(( day - 1 )) days earlier than the given date.
      # The Monday two weeks earlier is 14 days earlier still.

      date -d "$thedate -$(( day - 1 + 14 )) days" +"$thedate --> %Y%m%d"
      done


      Output:



      20190315 --> 20190225
      20180217 --> 20180129
      20170914 --> 20170828


      The difficult bit about this is to figure out how to construct the correct --date or -d string for GNU date to compute the final date. I opted for computing the day of week of the given date, and then using that to compute a date string that offsets the given date by a number of days so that the resulting date is the Monday two weeks earlier.



      The actual strings that ends up being used for the option argument to -d in the above script, using the dates given in the script, are



      20190315 -18 days
      20180217 -19 days
      20170914 -17 days


      Condensing the script into a single command that does the computation for a single date in $thedate:



      date -d "$thedate -$(date -d "$thedate" +%u) days -13 days" +%Y%m%d


      or



      date -d "$thedate -$(date -d "$thedate" +"-%u days -13 days")" +%Y%m%d






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited 9 hours ago

























      answered yesterday









      KusalanandaKusalananda

      137k17258426




      137k17258426












      • Thank you. This works great.

        – Eternal Learner
        12 hours ago

















      • Thank you. This works great.

        – Eternal Learner
        12 hours ago
















      Thank you. This works great.

      – Eternal Learner
      12 hours ago





      Thank you. This works great.

      – Eternal Learner
      12 hours ago













      3














      On at least Debian there is a faketime package



      faketime '2019-03-15' date
      Fri 15 Mar 00:00:00 GMT 2019

      faketime '2019-03-15' date --date 'last monday - 14 days'
      Mon 25 Feb 00:00:00 GMT 2019





      share|improve this answer



























        3














        On at least Debian there is a faketime package



        faketime '2019-03-15' date
        Fri 15 Mar 00:00:00 GMT 2019

        faketime '2019-03-15' date --date 'last monday - 14 days'
        Mon 25 Feb 00:00:00 GMT 2019





        share|improve this answer

























          3












          3








          3







          On at least Debian there is a faketime package



          faketime '2019-03-15' date
          Fri 15 Mar 00:00:00 GMT 2019

          faketime '2019-03-15' date --date 'last monday - 14 days'
          Mon 25 Feb 00:00:00 GMT 2019





          share|improve this answer













          On at least Debian there is a faketime package



          faketime '2019-03-15' date
          Fri 15 Mar 00:00:00 GMT 2019

          faketime '2019-03-15' date --date 'last monday - 14 days'
          Mon 25 Feb 00:00:00 GMT 2019






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          roaimaroaima

          45.8k758124




          45.8k758124





















              2














              $ date
              Wed Mar 20 15:02:23 MST 2019
              $ date -d "last-monday"
              Mon Mar 18 00:00:00 MST 2019
              $ date -d "last-monday - 1 week"
              Mon Mar 11 00:00:00 MST 2019





              share|improve this answer


















              • 2





                The issue seems to be finding the date of the Monday two weeks before a particular date.

                – Kusalananda
                yesterday















              2














              $ date
              Wed Mar 20 15:02:23 MST 2019
              $ date -d "last-monday"
              Mon Mar 18 00:00:00 MST 2019
              $ date -d "last-monday - 1 week"
              Mon Mar 11 00:00:00 MST 2019





              share|improve this answer


















              • 2





                The issue seems to be finding the date of the Monday two weeks before a particular date.

                – Kusalananda
                yesterday













              2












              2








              2







              $ date
              Wed Mar 20 15:02:23 MST 2019
              $ date -d "last-monday"
              Mon Mar 18 00:00:00 MST 2019
              $ date -d "last-monday - 1 week"
              Mon Mar 11 00:00:00 MST 2019





              share|improve this answer













              $ date
              Wed Mar 20 15:02:23 MST 2019
              $ date -d "last-monday"
              Mon Mar 18 00:00:00 MST 2019
              $ date -d "last-monday - 1 week"
              Mon Mar 11 00:00:00 MST 2019






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered yesterday









              DopeGhotiDopeGhoti

              46.5k56190




              46.5k56190







              • 2





                The issue seems to be finding the date of the Monday two weeks before a particular date.

                – Kusalananda
                yesterday












              • 2





                The issue seems to be finding the date of the Monday two weeks before a particular date.

                – Kusalananda
                yesterday







              2




              2





              The issue seems to be finding the date of the Monday two weeks before a particular date.

              – Kusalananda
              yesterday





              The issue seems to be finding the date of the Monday two weeks before a particular date.

              – Kusalananda
              yesterday











              0














              The overkill solution:



              Create a bare-bones virtual machine. 
              Run it in single user mode,
              so no background services are running. 
              Just to be sure, double-check that NTP is not running.



              Then set the date to whatever you want to set it to,
              and do your tests.






              share|improve this answer



























                0














                The overkill solution:



                Create a bare-bones virtual machine. 
                Run it in single user mode,
                so no background services are running. 
                Just to be sure, double-check that NTP is not running.



                Then set the date to whatever you want to set it to,
                and do your tests.






                share|improve this answer

























                  0












                  0








                  0







                  The overkill solution:



                  Create a bare-bones virtual machine. 
                  Run it in single user mode,
                  so no background services are running. 
                  Just to be sure, double-check that NTP is not running.



                  Then set the date to whatever you want to set it to,
                  and do your tests.






                  share|improve this answer













                  The overkill solution:



                  Create a bare-bones virtual machine. 
                  Run it in single user mode,
                  so no background services are running. 
                  Just to be sure, double-check that NTP is not running.



                  Then set the date to whatever you want to set it to,
                  and do your tests.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  G-ManG-Man

                  13.5k93768




                  13.5k93768





















                      -1














                      Use the date command's -s/--set option:



                      # date
                      Wed Mar 20 23:02:18 CET 2019
                      # date -s '20190315' > /dev/null; date -d 'last-monday - 14 days'
                      Mon Feb 25 00:00:00 CET 2019


                      Depending on your system, you might have to prefix with sudo or reset afterwards via ntpdate






                      share|improve this answer








                      New contributor




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















                      • 1





                        Setting the system's clock seems like overkill just to get the correct output. It may also confuse certain services and scheduled tasks, and other users of the system if it's a multi-user system.

                        – Kusalananda
                        yesterday












                      • @Kusalananda I agree, in principle, but most modern systems will automatically resync via ntp anyway. When I tested this, date returned the correct time immediately afterwards; hence the ; instead of using two separate commands to show what I'm doing. But if you really don't want to touch your system time, there does exist a faketime package.

                        – Entropy0
                        yesterday











                      • The ntpd daemon won't resync if you exceed its the 300 second variance.

                        – roaima
                        yesterday











                      • Then there is something else going on in my system (Mint 19), because 5d > 300s and as I said: running above command didn't affect anything beyond the commands in the current line. In fact: # date -s '19700102' ; date ; sleep 1 ; date yields Fri Jan 2 00:00:00 CET 1970 Fri Jan 2 00:00:00 CET 1970 Wed Mar 20 23:49:26 CET 2019

                        – Entropy0
                        yesterday












                      • Maybe you're running ntpdate from cron (ugh), or perhaps chrony has a larger leeway. Or there again there's whatever the systemd borg has done to NTP.

                        – roaima
                        yesterday
















                      -1














                      Use the date command's -s/--set option:



                      # date
                      Wed Mar 20 23:02:18 CET 2019
                      # date -s '20190315' > /dev/null; date -d 'last-monday - 14 days'
                      Mon Feb 25 00:00:00 CET 2019


                      Depending on your system, you might have to prefix with sudo or reset afterwards via ntpdate






                      share|improve this answer








                      New contributor




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















                      • 1





                        Setting the system's clock seems like overkill just to get the correct output. It may also confuse certain services and scheduled tasks, and other users of the system if it's a multi-user system.

                        – Kusalananda
                        yesterday












                      • @Kusalananda I agree, in principle, but most modern systems will automatically resync via ntp anyway. When I tested this, date returned the correct time immediately afterwards; hence the ; instead of using two separate commands to show what I'm doing. But if you really don't want to touch your system time, there does exist a faketime package.

                        – Entropy0
                        yesterday











                      • The ntpd daemon won't resync if you exceed its the 300 second variance.

                        – roaima
                        yesterday











                      • Then there is something else going on in my system (Mint 19), because 5d > 300s and as I said: running above command didn't affect anything beyond the commands in the current line. In fact: # date -s '19700102' ; date ; sleep 1 ; date yields Fri Jan 2 00:00:00 CET 1970 Fri Jan 2 00:00:00 CET 1970 Wed Mar 20 23:49:26 CET 2019

                        – Entropy0
                        yesterday












                      • Maybe you're running ntpdate from cron (ugh), or perhaps chrony has a larger leeway. Or there again there's whatever the systemd borg has done to NTP.

                        – roaima
                        yesterday














                      -1












                      -1








                      -1







                      Use the date command's -s/--set option:



                      # date
                      Wed Mar 20 23:02:18 CET 2019
                      # date -s '20190315' > /dev/null; date -d 'last-monday - 14 days'
                      Mon Feb 25 00:00:00 CET 2019


                      Depending on your system, you might have to prefix with sudo or reset afterwards via ntpdate






                      share|improve this answer








                      New contributor




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










                      Use the date command's -s/--set option:



                      # date
                      Wed Mar 20 23:02:18 CET 2019
                      # date -s '20190315' > /dev/null; date -d 'last-monday - 14 days'
                      Mon Feb 25 00:00:00 CET 2019


                      Depending on your system, you might have to prefix with sudo or reset afterwards via ntpdate







                      share|improve this answer








                      New contributor




                      Entropy0 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 answer



                      share|improve this answer






                      New contributor




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









                      answered yesterday









                      Entropy0Entropy0

                      562




                      562




                      New contributor




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





                      New contributor





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






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







                      • 1





                        Setting the system's clock seems like overkill just to get the correct output. It may also confuse certain services and scheduled tasks, and other users of the system if it's a multi-user system.

                        – Kusalananda
                        yesterday












                      • @Kusalananda I agree, in principle, but most modern systems will automatically resync via ntp anyway. When I tested this, date returned the correct time immediately afterwards; hence the ; instead of using two separate commands to show what I'm doing. But if you really don't want to touch your system time, there does exist a faketime package.

                        – Entropy0
                        yesterday











                      • The ntpd daemon won't resync if you exceed its the 300 second variance.

                        – roaima
                        yesterday











                      • Then there is something else going on in my system (Mint 19), because 5d > 300s and as I said: running above command didn't affect anything beyond the commands in the current line. In fact: # date -s '19700102' ; date ; sleep 1 ; date yields Fri Jan 2 00:00:00 CET 1970 Fri Jan 2 00:00:00 CET 1970 Wed Mar 20 23:49:26 CET 2019

                        – Entropy0
                        yesterday












                      • Maybe you're running ntpdate from cron (ugh), or perhaps chrony has a larger leeway. Or there again there's whatever the systemd borg has done to NTP.

                        – roaima
                        yesterday













                      • 1





                        Setting the system's clock seems like overkill just to get the correct output. It may also confuse certain services and scheduled tasks, and other users of the system if it's a multi-user system.

                        – Kusalananda
                        yesterday












                      • @Kusalananda I agree, in principle, but most modern systems will automatically resync via ntp anyway. When I tested this, date returned the correct time immediately afterwards; hence the ; instead of using two separate commands to show what I'm doing. But if you really don't want to touch your system time, there does exist a faketime package.

                        – Entropy0
                        yesterday











                      • The ntpd daemon won't resync if you exceed its the 300 second variance.

                        – roaima
                        yesterday











                      • Then there is something else going on in my system (Mint 19), because 5d > 300s and as I said: running above command didn't affect anything beyond the commands in the current line. In fact: # date -s '19700102' ; date ; sleep 1 ; date yields Fri Jan 2 00:00:00 CET 1970 Fri Jan 2 00:00:00 CET 1970 Wed Mar 20 23:49:26 CET 2019

                        – Entropy0
                        yesterday












                      • Maybe you're running ntpdate from cron (ugh), or perhaps chrony has a larger leeway. Or there again there's whatever the systemd borg has done to NTP.

                        – roaima
                        yesterday








                      1




                      1





                      Setting the system's clock seems like overkill just to get the correct output. It may also confuse certain services and scheduled tasks, and other users of the system if it's a multi-user system.

                      – Kusalananda
                      yesterday






                      Setting the system's clock seems like overkill just to get the correct output. It may also confuse certain services and scheduled tasks, and other users of the system if it's a multi-user system.

                      – Kusalananda
                      yesterday














                      @Kusalananda I agree, in principle, but most modern systems will automatically resync via ntp anyway. When I tested this, date returned the correct time immediately afterwards; hence the ; instead of using two separate commands to show what I'm doing. But if you really don't want to touch your system time, there does exist a faketime package.

                      – Entropy0
                      yesterday





                      @Kusalananda I agree, in principle, but most modern systems will automatically resync via ntp anyway. When I tested this, date returned the correct time immediately afterwards; hence the ; instead of using two separate commands to show what I'm doing. But if you really don't want to touch your system time, there does exist a faketime package.

                      – Entropy0
                      yesterday













                      The ntpd daemon won't resync if you exceed its the 300 second variance.

                      – roaima
                      yesterday





                      The ntpd daemon won't resync if you exceed its the 300 second variance.

                      – roaima
                      yesterday













                      Then there is something else going on in my system (Mint 19), because 5d > 300s and as I said: running above command didn't affect anything beyond the commands in the current line. In fact: # date -s '19700102' ; date ; sleep 1 ; date yields Fri Jan 2 00:00:00 CET 1970 Fri Jan 2 00:00:00 CET 1970 Wed Mar 20 23:49:26 CET 2019

                      – Entropy0
                      yesterday






                      Then there is something else going on in my system (Mint 19), because 5d > 300s and as I said: running above command didn't affect anything beyond the commands in the current line. In fact: # date -s '19700102' ; date ; sleep 1 ; date yields Fri Jan 2 00:00:00 CET 1970 Fri Jan 2 00:00:00 CET 1970 Wed Mar 20 23:49:26 CET 2019

                      – Entropy0
                      yesterday














                      Maybe you're running ntpdate from cron (ugh), or perhaps chrony has a larger leeway. Or there again there's whatever the systemd borg has done to NTP.

                      – roaima
                      yesterday






                      Maybe you're running ntpdate from cron (ugh), or perhaps chrony has a larger leeway. Or there again there's whatever the systemd borg has done to NTP.

                      – roaima
                      yesterday











                      Eternal Learner is a new contributor. Be nice, and check out our Code of Conduct.









                      draft saved

                      draft discarded


















                      Eternal Learner is a new contributor. Be nice, and check out our Code of Conduct.












                      Eternal Learner is a new contributor. Be nice, and check out our Code of Conduct.











                      Eternal Learner 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%2f507549%2fget-date-of-monday-two-weeks-ago-from-particular-date-using-gnu-date%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

                      getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                      Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                      Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.