?
Solved

need to get 2 character day from date all the time

Posted on 2006-07-05
7
Medium Priority
?
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Accepted Solution

by:
bengtbj earned 400 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 400 total points
ID: 17046247
CDA=`printf "%02d" \`date +%d\``
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 200 total points
ID: 17052791
Tintin with a bash only solution ;-)
I'd vote for:
CDA=`date +%d`
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 400 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 400 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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