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
How to remove leading zeros in a variable or a string? The variable x is declared using the typeset command. The -Z option of typeset will strip the leading zeros present when used along with -L option. The expression '^0*' will search for a sequence of 0's in the beginning and delete them.
date +%S. Displays seconds [00-59] date +%N. Displays in Nanoseconds.
Bash Date format YYYY-MM-DD To format date in YYYY-MM-DD format, use the command date +%F or printf "%(%F)T\n" $EPOCHSECONDS . The %F option is an alias for %Y-%m-%d . This format is the ISO 8601 format.
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 possibleAfter 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With