user1801934 user1801934 - 11 months ago 38
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"