Computing.Net > Forums > Programming > date format in ksh

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

date format in ksh

Reply to Message Icon

Name: cesar_NZ
Date: October 7, 2008 at 15:17:03 Pacific
OS: solaris
CPU/Ram: na
Product: na
Comment:

hi all,
am trying to get today's date in the following format :

m/d/yy i.e

single digit for month unless its a double digit (8 rather than 08),
single digit for day unless its a double digit and double digit for year.


have tried 'date +%m/%d/%y' but it keeps giving me double digits where not needed i.e 10/08/08


thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: October 7, 2008 at 19:06:48 Pacific
Reply:

Try:

$((`date +%m`))/$((`date +%d`))/`date +%y`


0

Response Number 2
Name: cesar_NZ
Date: October 7, 2008 at 19:46:39 Pacific
Reply:

thanks for the reply, but it didnt work. date +%d give double digits. have tried date "+%Om/%Oe/%y" but that has a space in number of days which is not what i wanted e.g 10/ 8/08


0

Response Number 3
Name: Razor2.3
Date: October 7, 2008 at 20:28:29 Pacific
Reply:

date +%d give double digits
Right, but on my platform, that gets rid of the preceding '0.' If you didn't try it with the $((` `)), then try it.


0

Response Number 4
Name: cesar_NZ
Date: October 8, 2008 at 15:27:41 Pacific
Reply:

hi,
yap i did try that but it didnt work. must be specific to my platform.

thanks anyway.


0

Response Number 5
Name: cesar_NZ
Date: October 8, 2008 at 17:31:04 Pacific
Reply:

dont know why i didnt think of this before, heres the solution :


date +%Om/%Oe/%y | sed 's/ //g'


output is : 10/9/08 which is what i wanted :)


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: date format in ksh

Date Calculations in KSH www.computing.net/answers/programming/date-calculations-in-ksh/4022.html

Change Date Format in XP www.computing.net/answers/programming/change-date-format-in-xp/16292.html

Problems with date command in W2003 Server www.computing.net/answers/programming/problems-with-date-command-in-w2003-server/19348.html