Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

need to get 2 character day from date all the time

Posted on 2006-07-05
7
Medium Priority
?
324 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
Industry Leaders: 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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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

604 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