I'm testing my backup script on Linux and when I try to set the date to '20141019' I have this error:
# date +%Y%m%d -s "20141019"
date: invalid date ‘20141019’
This works:
# date +%Y%m%d -s "20141018"
20141018
# date +%Y%m%d -s "20141020"
20141020
Another problem to set date to 28 days ago at 20141116
# date -d '28 day ago' +%Y-%m-%d
2014-10-18
// at 20141117:
# date -d '28 day ago' +%Y-%m-%d
2014-10-20
What is wrong with linux date v. 8.21?
You can try this command.
Command: timedatectl set-time YYYY-MM-DD HH:MM:SS
Set date and time: timedatectl set-time '2015-11-23 08:10:40'
Set only date: timedatectl set-time '2015-12-01'
Set only time: timedatectl set-time '10:42:43'
I just tried this tutorial
It give you multiple solutions to set date and time, may be you can find something to solve your problem.
This is due to a problem with the timezone DST - if the timezone has entered the daylight saving time, then it won't have the midnight to be counted on GNU date:
~$ TZ=America/Sao_Paulo date -d '20161016 + 1 day'
date: invalid date `20161016 + 1 day'
~$ TZ=America/Sao_Paulo date -d '20171015 + 1 day'
date: invalid date `20171015 + 1 day'
~$ TZ=America/Sao_Paulo date -d '20181021 + 1 day'
date: invalid date `20181021 + 1 day'
In this case, you can use UTC for that:
~$ TZ=UTC date -d '20171015 + 1 day'
Mon Oct 16 00:00:00 UTC 2017
So try:
~$ TZ=UTC date +%Y%m%d -d "20141019"
20141019
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.