Invalid date


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Invalid date

Hi, I have a function to calculate "yesterday" in format YYYYMMDD:

Code:
desa_ev9 # date +"%Y%m%d" --date "-1 day 20180701"
20180630

desa_ev9 # date +"%Y%m%d" --date "-1 day 20180720"
20180719

desa_ev9 # date +"%Y%m%d" --date "-1 day 20190101"
20181231

desa_ev9 # date +"%Y%m%d" --date "-1 day 20180913"
20180912

Works correctly but....

Code:
desa_ev9 # date +"%Y%m%d" --date "-1 day 20180812"
date: invalid date `-1 day 20180812'

What is the problem?




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 09-26-2018 at 11:29 AM.. Reason: Added CODE tags.
# 2  
Welcome to the forum.

Works for me:
Code:
date +"%Y%m%d" --date "-1 day 20180812"
20180811

Anything special that you did between the before last and last command?
# 3  
Now I see, you want 1 day less than a given date.
It should work. I successfully checked with several versions of GNU date.
If even
Code:
date +"%Y%m%d" --date "20180812 - 1 day"

does not work, then I suspect a bug in your date program.

Last edited by MadeInGermany; 09-26-2018 at 03:22 PM..
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Date: invalid date trying to set Linux date in specific format
umen
i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date 19-01-2017 00:05:01 Please use CODE tags...... Shell Programming and Scripting
7
Shell Programming and Scripting
Converting a date to friday date and finding Min/Max date
2001.arun
Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to...... Shell Programming and Scripting
10
Shell Programming and Scripting
Valid and invalid date in the file
bmk
Hi All, How to validate the 4th column,it is date column in the file, if it valid move to valid file else moved invalid file. 9f680174-cb87|20077337254|0|20120511|N 9f680174-cb88|20077337254|0|20120534|N i want two file valid.txt and invalid.txt Thanks,... Shell Programming and Scripting
7
Shell Programming and Scripting
date: invalid date
Jcpratap
Hi All, I am trying to convert the date of all files under a directory in seconds, PFB script a=`ls -lrt | wc -l` echo $a for ((i=1;i<=$a;i++)) do A=`ls -lrt | awk '{print $6,$7,$8}' | head -$i | tail -1` echo ${A} date -d '${A}' +%s donebut I am getting error date: invalid date...... Shell Programming and Scripting
1
Shell Programming and Scripting
date: invalid date `19010101'
freizl
why date -d "19010101" gets error " date: invalid date `19010101' " but date -d "19020101" is fine? Any approach to fix that? Thank you.... Shell Programming and Scripting
8
Shell Programming and Scripting