Chris
Chris

Reputation: 1229

Date - Month in bash without leading 0 or space?

Anyone know how to display the date like this?

7-1-2019

I currently have this which adds leading 0 to the month

$(LC_ALL=nn_NO.UTF-8 date +'%-d-%m-%Y')

like this

7-01-2019

I use these in lynx dump commands

Upvotes: 24

Views: 19523

Answers (1)

Lev Levitsky
Lev Levitsky

Reputation: 65811

You have already removed the padding for the day, why not do the same for the month?

$ date +'%-d-%-m-%Y'
7-1-2019

Here's a list of all padding modifiers from man date:

By default, date pads numeric fields with zeroes. The following optional flags may follow '%':

- (hyphen) do not pad the field

_ (underscore) pad with spaces

0 (zero) pad with zeros

^ use upper case if possible

# use opposite case if possible

After any flags comes an optional field width, as a decimal number; then an optional modifier, which is either E to use the locale's alternate representations if available, or O to use the locale's alternate numeric symbols if available.

Upvotes: 73

Related Questions