I tried using $(date) in my bash shell script, however, I want the date in YYYY-MM-DD format.
How do I get this?
Bash - YYYY-MM-DD format date in shell script
bashdateshellstrftime
Related Question
- Bash - How to check if a directory exists in a Bash shell script
- Bash - How to get the source directory of a Bash script from within the script itself
- Python - How to execute a program or call a system command
- Linux - How to prompt for Yes/No/Cancel input in a Linux shell script
- Bash - In the shell, what does ” 2>&1 ” mean
- Linux - Looping through the content of a file in Bash
- Javascript - How to get the current date in JavaScript
- Javascript - How to format a JavaScript date
- Bash - Check existence of input argument in a Bash shell script
- Bash - Echo newline in Bash prints literal \n
Best Solution
In bash (>=4.2) it is preferable to use printf's built-in date formatter (part of bash) rather than the external
date(usually GNU date).As such:
In bash (<4.2):
Other available date formats can be viewed from the date man pages (for external non-bash specific command):