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
  • 1
    You could try date -d "1970-01-01 UTC $i seconds +10 days" '+%F %T', which should be equivalent, I think – steeldriver Feb 5 '16 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 Feb 6 '16 at 2:52

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
  • Add a LC_TIME=C, as this: date -d "$(LC_TIME=C date -d @1469411110)+10 days" +'%F %T' to avoid locale problems. – user79743 Feb 6 '16 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.