LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 06-27-2006, 04:52 AM   #1
menator
LQ Newbie
 
Registered: Nov 2005
Posts: 11

Rep: Reputation: 0
Date command - month of year, blank padded?


Im trying to create a variable in my shell script that contains todays date but with the day and month padded with blanks:


Code:
date +%e/%m/%Y
This would return 27/06/2006. The day of the month is padded with blanks so that you get '1' instead of '01' in the day (e.g. 1/06/2006 instead of 01/06/2006). The problem is that there doesnt seem to be a way to do the same for the month of the year...well not according to the man page anyway.

Is there I way i can achieve this?
 
Old 06-27-2006, 05:12 AM   #2
kassle
Member
 
Registered: Jan 2006
Distribution: Linux From Scratch falling in love with Slackware
Posts: 44

Rep: Reputation: 15
ok, so you want to show 1/6/2006. try the following script
Quote:
month=`date +%m`
zero=`echo $month | cut -c 1`
if [ $zero -le 0 ]; then
month=`echo $month | cut -c 2`
fi
echo `date +%e`"/$month/"`date +%Y`
 
Old 06-27-2006, 05:36 AM   #3
menator
LQ Newbie
 
Registered: Nov 2005
Posts: 11

Original Poster
Rep: Reputation: 0
oh that worked perfectly - thanks for the help
 
Old 06-27-2006, 06:00 AM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
You have other options too...

Code:
date +%_d/%m/%y
From the man page on my machine:
Code:
%e     day of month, space padded; same as %_d
<EDIT> ok.. I can read...

try:
Code:
date +%_d/%_m/%y
You can put the _ in any construct to get space padding...

Code:
j_shaw@jshawlptp:~$ date +%_d/%_m/%y
27/ 6/06

Last edited by jtshaw; 06-27-2006 at 06:03 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
transform month number to month name in php ALInux Programming 1 11-09-2005 10:45 AM
Multicount in PHP , displays visits on current day, week, month, year and total visit xbaez Programming 1 04-24-2005 02:50 AM
How do I print using format that padded space between printed value ? Linh Programming 2 06-18-2004 03:22 PM
Starting day of month, month length chrisk5527 Programming 2 03-03-2004 04:03 PM
How to get the month in one digit instead of two digits in the "date" command? aadaileh Programming 7 02-05-2004 04:57 PM


All times are GMT -5. The time now is 06:43 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration