Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date format 1

Status
Not open for further replies.

jaykjoe

Programmer
Jan 15, 2002
10
US
I would like know if there's a parameter for the date function in UNIX that shows the day as 1 digit instead of 2 digits?

For example, tomorrow is 02/03 (date +%m/%d). How can I make it show up as 2/3 with this date function. I can write a script to strip off the leading zeros, but I would like to know if this is possible using the date function. It would save me a lot more time. Thanks.
 
You can use this:

date +%m/%e|sed -e 's/^0//' -e s'/ //'

The %e will give the day but with a blank space before it, that is what the -e 's/ //' is for and the %m will only give the 0(MON_NUM) which the first sed statement is for.
 
Thanks. Not exactly what I was looking for, but it will do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top