user1801934 user1801934 - 1 year ago 44
Bash Question

date -d option usage in Shell Scripting

date -d '($VAR) hours ago' +"%Y-%m-%d %H"

This gives me the wrong result. How do I pass in the variable in date -d option?


Variables won't be expanded when put inside single quotes, use double quotes instead:

date -d "$VAR hours ago" +"%Y-%m-%d %H"