need to get 2 character day from date all the time

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
AlexF777Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
bengtbjConnect With a Mentor Commented:
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
 
TintinConnect With a Mentor Commented:
CDA=`printf "%02d" \`date +%d\``
0
 
ahoffmannConnect With a Mentor Commented:
Tintin with a bash only solution ;-)
I'd vote for:
CDA=`date +%d`
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
TintinConnect With a Mentor Commented:
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
 
bengtbjConnect With a Mentor Commented:
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
 
ahoffmannCommented:
Tintin, which OS's date does not use leading zeros (I'm learning too)
0
 
TintinCommented:
Doh!  What was I thinking!!  Not sure how I got on to that line of thought.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.