19

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

1 Answer 1

52

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.

1
  • Thanks. I didnt actually know I was doing that.
    – Chris
    Jan 6, 2019 at 22:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.