I tried using $(date)
in my bash shell script, however I want the date in YYYY-MM-DD +DAY + Mounth
format.(if the month is 9 I do not want to display 09) How do I get this?
Asked
Active
Viewed 1,724 times
-1

Piccolo
- 11
- 5
-
2Possible duplicate of [Convert date formats in bash](https://stackoverflow.com/questions/6508819/convert-date-formats-in-bash) – oguz ismail Sep 17 '19 at 20:04
-
So would today be `2019-09-17 +17 +9`? – chepner Sep 17 '19 at 20:06
-
2019-09-17 Tuesday September ,but I want to display in whatever language I want. I have this : `date "+%A %B %d %T %y" ` – Piccolo Sep 17 '19 at 20:07
-
Hmm, so where does the _if the month is 9 I do not want to display 09_ come to picture? – James Brown Sep 17 '19 at 20:09
1 Answers
0
Some versions of date
can't display the month without the leading zero. You can use sed
to remove it, though: the month is the only number surrounded by dashes:
date '+%Y-%m-%d %A %B' | sed 's/-0\([0-9]\)-/-\1-/'
Some versions support the padding modifiers. To turn padding off, use a dash:
date '+%Y-%-m-%d %A %B'
~
To change the language, just specify the locale:
$ LC_ALL=it_IT.UTF-8 date '+%Y-%m-%d %A %B' | sed 's/-0\([0-9]\)-/-\1-/'
2019-9-17 martedì settembre

choroba
- 231,213
- 25
- 204
- 289
-
-
-
One more question. What can i do when i have the code in this format`LC_ALL=it_IT.UTF-8 date '+%Y-%m %B-%d %A' | sed 's/-0\([0-9]\)-/-\1-/' ` – Piccolo Sep 17 '19 at 20:23
-
-
Either specify `%-m` if your version of `date` supports it, or remove the dash between a digit and zero: `sed 's/\([0-9]\)-0/\1-/'`. – choroba Sep 17 '19 at 20:28