• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

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
0
AlexF777
Asked:
AlexF777
  • 3
  • 2
  • 2
5 Solutions
 
bengtbjCommented:
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
 
TintinCommented:
CDA=`printf "%02d" \`date +%d\``
0
 
ahoffmannCommented:
Tintin with a bash only solution ;-)
I'd vote for:
CDA=`date +%d`
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TintinCommented:
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
 
bengtbjCommented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now