PUSTAKAKORAN.COM PUSTAKAKORAN.COM - 2 months ago 13
Linux Question

Code for linux date YYY-M-D

In the linux date command, I use this code:

TODAY=$(date +"%Y-%m-%d")


sample output YYYY-MM-DD, such as 2016-09-05.

If I want output date YYYY-M-D, such as 2016-9-5, what should I do with this code?

Answer

Do it:

TODAY=$(date +"%Y-%-m-%-d")

Explaining, the - will remove the leading zeros...

Example:

September month...

%m returns 09
%-m returns 9