1

I've file contain many of epoch / UNIX timestamps need to add for example +10 days for output date so then I will get new date

and I've create bash script with date command but seems doesn't work

for i in `cat stamp.txt`; do
date -d @$i "+10 days" '+%F %T'

got error like

date: invalid option -- '1'
Try `date --help' for more information.

since if i run it for date of today is work

date -d "+10 days" is work 

also the convert is work

date -d @1469411110 '+%F %T' is work
2
  • 1
    You could try date -d "1970-01-01 UTC $i seconds +10 days" '+%F %T', which should be equivalent, I think Commented Feb 5, 2016 at 1:47
  • @steeldriver Well ... yes, is equivalent. If there is no DST in effect, and a local time is acceptable. Better to use date -ud .....
    – user79743
    Commented Feb 6, 2016 at 2:52

1 Answer 1

3

Try this

$ date -d @1469411110
Sun Jul 24 21:45:10 EDT 2016

$ date -d @1469411110 '+%F +T'
2016-07-24 21:34:36 EST 2016

$ date -d "$(date -d @1469411110)+10 days"
Wed Aug  3 21:45:10 EDT 2016

$ date -d "$(date -d @1469411110)+10 days" +'%F %T'
2016-08-03 21-45-10
2
  • Add a LC_TIME=C, as this: date -d "$(LC_TIME=C date -d @1469411110)+10 days" +'%F %T' to avoid locale problems.
    – user79743
    Commented Feb 6, 2016 at 2:47
  • I don't get the same results here (date (GNU coreutils) 8.26). The date arithmetic variants (+10 days) give me 2016-07-25 07:45:10 instead of the expected 2016-08-03 21:45:10. Is this a regression bug? Commented Jan 22, 2020 at 22:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .