Solved

need to get 2 character day from date all the time

Posted on 2006-07-05
7
309 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Bad Block Relocation for Synchronous GLVM AIX 7.1 2 76
phantom space used up on RHEL?  (du shows no space used) 1 81
How to Change Interface on Cisco IOU 11 110
MarkLogic 1 89
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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 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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

840 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