Solved

need to get 2 character day from date all the time

Posted on 2006-07-05
7
301 Views
Last Modified: 2011-10-03
gfs1 Jax:alex /home/alex> CDA=`date | cut -c9-10`                
gfs1 Jax:alex /home/alex> echo $CDA                              
5                                                                
gfs1 Jax:alex /home/alex>                                        

Thanks in advance,
-Alex
0
Comment
Question by:AlexF777
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Accepted Solution

by:
bengtbj earned 100 total points
ID: 17042873
OK, you have two options.

One, use date formating
> CDA=`date +%d`
That will return day of moth with two didgits
(So today 05 :) )
 
otherwise you could use
CDA=date | cut -c9-10`
printf "%02s"
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 100 total points
ID: 17046247
CDA=`printf "%02d" \`date +%d\``
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 50 total points
ID: 17052791
Tintin with a bash only solution ;-)
I'd vote for:
CDA=`date +%d`
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 100 total points
ID: 17069349
ahoffman.

Doesn't matter if you are using bash, ksh, sh or zsh.

CDA=`date +%d`

is not going to give you a zero padded 2 digit date.
0
 
LVL 1

Assisted Solution

by:bengtbj
bengtbj earned 100 total points
ID: 17071305
Tintin:

From date's man pages

%d Displays the day of the month as a decimal number (01-31). In a two-digit
field, a 0 is used as leading space fill.

However, some shells might remove the leading zero, in that case you could try
CDA="`date +%d`"
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17071332
Tintin, which OS's date does not use leading zeros (I'm learning too)
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17077251
Doh!  What was I thinking!!  Not sure how I got on to that line of thought.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now