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
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
New contributor
add a comment |
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
New contributor
You'd want a way to get (respectively to your example) results such as:20190225
and20180129
and20170828
, am I correct ?
– LL3
yesterday
add a comment |
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
New contributor
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
linux date
New contributor
New contributor
edited yesterday
Kusalananda
137k17258426
137k17258426
New contributor
asked yesterday
Eternal LearnerEternal Learner
1032
1032
New contributor
New contributor
You'd want a way to get (respectively to your example) results such as:20190225
and20180129
and20170828
, am I correct ?
– LL3
yesterday
add a comment |
You'd want a way to get (respectively to your example) results such as:20190225
and20180129
and20170828
, 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
add a comment |
5 Answers
5
active
oldest
votes
#!/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
Thank you. This works great.
– Eternal Learner
12 hours ago
add a comment |
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
add a comment |
$ 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
2
The issue seems to be finding the date of the Monday two weeks before a particular date.
– Kusalananda
yesterday
add a comment |
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.
add a comment |
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
New contributor
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 afaketime
package.
– Entropy0
yesterday
Thentpd
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
yieldsFri 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 runningntpdate
fromcron
(ugh), or perhapschrony
has a larger leeway. Or there again there's whatever thesystemd
borg has done to NTP.
– roaima
yesterday
|
show 1 more comment
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
#!/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
Thank you. This works great.
– Eternal Learner
12 hours ago
add a comment |
#!/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
Thank you. This works great.
– Eternal Learner
12 hours ago
add a comment |
#!/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
#!/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
edited 9 hours ago
answered yesterday
KusalanandaKusalananda
137k17258426
137k17258426
Thank you. This works great.
– Eternal Learner
12 hours ago
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered yesterday
roaimaroaima
45.8k758124
45.8k758124
add a comment |
add a comment |
$ 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
2
The issue seems to be finding the date of the Monday two weeks before a particular date.
– Kusalananda
yesterday
add a comment |
$ 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
2
The issue seems to be finding the date of the Monday two weeks before a particular date.
– Kusalananda
yesterday
add a comment |
$ 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
$ 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
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered yesterday
G-ManG-Man
13.5k93768
13.5k93768
add a comment |
add a comment |
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
New contributor
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 afaketime
package.
– Entropy0
yesterday
Thentpd
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
yieldsFri 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 runningntpdate
fromcron
(ugh), or perhapschrony
has a larger leeway. Or there again there's whatever thesystemd
borg has done to NTP.
– roaima
yesterday
|
show 1 more comment
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
New contributor
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 afaketime
package.
– Entropy0
yesterday
Thentpd
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
yieldsFri 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 runningntpdate
fromcron
(ugh), or perhapschrony
has a larger leeway. Or there again there's whatever thesystemd
borg has done to NTP.
– roaima
yesterday
|
show 1 more comment
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
New contributor
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
New contributor
New contributor
answered yesterday
Entropy0Entropy0
562
562
New contributor
New contributor
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 afaketime
package.
– Entropy0
yesterday
Thentpd
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
yieldsFri 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 runningntpdate
fromcron
(ugh), or perhapschrony
has a larger leeway. Or there again there's whatever thesystemd
borg has done to NTP.
– roaima
yesterday
|
show 1 more comment
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 afaketime
package.
– Entropy0
yesterday
Thentpd
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
yieldsFri 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 runningntpdate
fromcron
(ugh), or perhapschrony
has a larger leeway. Or there again there's whatever thesystemd
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
|
show 1 more comment
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
You'd want a way to get (respectively to your example) results such as:
20190225
and20180129
and20170828
, am I correct ?– LL3
yesterday