Latest LQ Deal: Linux Power User Bundle
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org How to get the month in one digit instead of two digits in the "date" command?
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 01-26-2004, 11:15 AM #1 aadaileh LQ Newbie   Registered: Jan 2004 Location: Germany Posts: 9 Rep: How to get the month in one digit instead of two digits in the "date" command? Hi there ... I am having problem with generating the following date format using the 'date command' in FreeBSD: 2004-1-26 The problem that I am getting the date written in this way: 2004-01-26 All I need is getting red of the zero which stands in fron of the month. Thanx a lot, Ahmed
 01-26-2004, 11:20 AM #2 aadaileh LQ Newbie   Registered: Jan 2004 Location: Germany Posts: 9 Original Poster Rep: Sorry ... I forgot the code I use ... date '+%Y-%m-%d' Thanx, Ahmed
 01-26-2004, 11:23 AM #3 jtshaw Senior Member   Registered: Nov 2000 Location: Seattle, WA USA Distribution: Ubuntu @ Home, RHEL @ Work Posts: 3,892 Blog Entries: 1 Rep: date +%Y-%-m-%-e
 01-28-2004, 02:58 AM #4 aadaileh LQ Newbie   Registered: Jan 2004 Location: Germany Posts: 9 Original Poster Rep: Thanx a lot for your response, but it seems that we have a missunderstanding here What I wanted to have is a "month" without leading zero not day. The command "date +%Y-%m-%e" gives back the days without leading zero. Thanx, Ahmed
 01-28-2004, 07:56 AM #5 jtshaw Senior Member   Registered: Nov 2000 Location: Seattle, WA USA Distribution: Ubuntu @ Home, RHEL @ Work Posts: 3,892 Blog Entries: 1 Rep: Ok, I took the leading 0 out of both. %m = month, %-m = month without leading zero. For some reason you took out the - I had inserted after the %. Use this command exactly as I have written it and only the month will lose the leading 0: date +%Y-%-m-%d Last edited by jtshaw; 01-28-2004 at 07:59 AM.
 01-28-2004, 08:17 AM #6 aadaileh LQ Newbie   Registered: Jan 2004 Location: Germany Posts: 9 Original Poster Rep: Thanx again... It works Regards,
 02-05-2004, 03:33 AM #7 aadaileh LQ Newbie   Registered: Jan 2004 Location: Germany Posts: 9 Original Poster Rep: Hi again, The command [date +%Y-%-m-%d] generates the desired format (I mean without the leading zero) in Linux-SuSe not in FreeBSD When I run it in FreeBSD it gives back the following output: prompt@user :/usr/local/etc > date +%Y-%-m-%d 2004--m-05 prompt@user :/usr/local/etc > date +%Y-%-m-%e 2004--m- 5 Do you have any idea to handle this problem? Regards, Ahmed
 02-05-2004, 04:57 PM #8 artur Member   Registered: Apr 2002 Location: Illinois, US Distribution: Red Hat, Fedora, Yellow Dog, Debian, FreeBSD, Embedix Posts: 106 Rep: In case you can't get it worked out with just date '+%Y-%m-%d' , try: Code: date '+%Y-%m-%d' | sed -e 's/-0/-/g' You can omit the "g" if you only want the first leading 0 omitted

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post granatica Linux - Software 5 07-25-2007 07:42 AM coolingtower Linux - Software 1 10-28-2005 11:49 AM sorcerer Linux - Distributions 1 08-21-2004 03:28 PM kaihuang Linux - General 0 10-21-2003 11:47 PM Supp0rtLinux Linux - Software 3 01-03-2003 09:29 PM

All times are GMT -5. The time now is 03:46 AM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -