Visit The New, Modern Unix Linux Community

single digit for day and month on date

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting single digit for day and month on date
# 1  
single digit for day and month on date

hi all,
how do i format the date command so it displays day and month in single digits i.e 8 instead of 08 ??

am using the command (in a ksh) : date +%D
output i get is 10/08/08

thanks in advance.
# 2  
date +"%Oe"
this will display date in single digit.. you wnat month too in single digit??
# 3  
oh yes please Smilie
# 4  
date +"%Oe" output has a space in it e.g " 8" is there a way to get rid of that space ??
# 5  
as alreay mention by above user u can use for get rid of space
date +"%Oe"| sed 's/ //'
# 6  
Then why don't you simply change any occurrence of /0 to just /

date +%D | sed 's%/0%/%g'

However, the manual page indicates that you can disable padding by putting a hyphen before the format code.

date +%Y/%-m/%d

Last edited by era; 10-08-2008 at 03:05 AM.. Reason: %-m/%-d

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #105
Difficulty: Easy
The programming interface, file abstraction, built-in networking and persistent background processing are all features and capabilities supported by a Unix or Linux OS.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to get first & last day of a month from current date?

Hi, I need the first & last day of a month from any given date. For better understanding, if i need to back-fill data for date 07/20/2019 i.e July 20 2019, i need the first & last day has 07/01/2019 - 07/31/2019. FYI: I'm using GIT BASH terminal. sample code: export DT=$(date --date='6 days... (2 Replies)
Discussion started by: Rocky975583
2 Replies

2. UNIX for Dummies Questions & Answers

[SOLVED] how to extract the day and month from a user supplied date ?

Hi All , I am trying to extract the day and month from a user supplied date . But not able . Please help . This is what I am trying to do , I have followed other articles in this scenario. userdate=$1 echo "Script parameter userdate is $userdate" The output of this is in this... (7 Replies)
Discussion started by: megha2525
7 Replies

3. Shell Programming and Scripting

convert two digit in to single digit...

Hi Guys. My Input: ABCD 12 00 KL ABCD 12 08 DL ABCD 12 10 KK ABCD 12 04 LL ABCD 13 00 LP ABCD 13 1O LS Output: ABCD 12 0 KL ABCD 12 8 DL ABCD 12 10 KK ABCD 12 4 LL ABCD 13 0 LP (2 Replies)
Discussion started by: pareshkp
2 Replies

4. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

5. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

6. Shell Programming and Scripting

Get yesterday's date in year-month-day format?

Dear All, Actually, i'm doing some reporting job and i need to pass yesterday's date in Year-Month-Day format(e.g. 2009-06-10) to another program for generating 2009-06-10 report. to get today's date, it's easy to just date '+%Y%m%d' , but no idea how can i get this kind of format for... (2 Replies)
Discussion started by: tiger2000
2 Replies

7. Shell Programming and Scripting

Single digit date to double digit date.

I have a var storing date var=`date` Now the date is returned as Mon Feb 2 00:25:48 PST 2009 Is there any way to check the date field alone ("2" in above case) and if its a single digit then add a prefix 0 to it and store the result in same variable "var" My intention in above case is... (3 Replies)
Discussion started by: villain41
3 Replies

8. Shell Programming and Scripting

month in single digit

hi all, how do i get the month in single digit in ksh script ?? my command for date is : /usr/bin/date +%Om/%Oe/%y | sed 's/ //g' which returns "01/16/09" but i need the output to be "1/16/09" i.e the month without leading zero. thanks in advance. (2 Replies)
Discussion started by: cesarNZ
2 Replies

9. Shell Programming and Scripting

needs to display month for previous day date

Hello, I wanted to display the month for previous day date. Like, today date is 18-Nov-2008. So the previous date is 17-Nov-2008. The output should be November. If the today date is 1-DEC-2008, then output should be NOVEMBER. If the today date is 1-JAN-2008, then output should be DECEMBER.... (4 Replies)
Discussion started by: govindts
4 Replies

10. Shell Programming and Scripting

Cron to run first day of month to calculate date 3 months ago

Hi, I would like to find out how can i calculate a date which is 3 months ago. I intend to run a cron job on the 1st of every month, and calculate the month 4 months earlier from the date. For example, if today's date is 1st May 2007, i would like to return 012007( January 2007). i can get... (1 Reply)
Discussion started by: new2ss
1 Replies

Featured Tech Videos