|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Date format - Shell scripting gurus please help
Guys:
I have the following script (from this forum) to calculate yesterdays date. However the format of the date that is output is yyyymd if the resultant date is single digit or the resultant month is a single digit month ( 01 - 09 ). How can I get the output to show the date in the following format yyyymmdd always instead of yyyymd Below is the script: date '+%Y %m %d' |#echo here shows date in the yyyymmdd format { read YEAR MONTH DAY #echo here shows date in the yyyymmdd format DAY1=`expr "$DAY" - 1` case "$DAY1" in 0) MONTH=`expr "$MONTH" - 1` echo $MONTH case "$MONTH" in 0) MONTH=12 YEAR=`expr "$YEAR" - 1` ;; esac DAY1=`cal $MONTH $YEAR | grep . | fmt -1 | tail -1` DAY2=`expr "$DAY1" - 1` echo $DAY1 # shows date in yyyymdd format if DAY1 is 200612 instead of 20060102 echo $DAY2 # shows date in yyyymdd format if DAY2 is 200611 instead of 20060101 esac } regards, m |
| Sponsored Links | ||
|
|
|
|||
|
Hi ,
have u used following command date -d "yesterday" '+%Y%m%d' |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| date issue-find prevoius date in a patricular format | bsandeep_80 | UNIX for Advanced & Expert Users | 3 | 11-15-2007 08:42 PM |
| convert mmddyy date format to ccyyddd format?? | Bhups | Shell Programming and Scripting | 2 | 09-28-2006 12:30 AM |
| difference between AIX shell scripting and Unix shell scripting. | haroonec | Shell Programming and Scripting | 2 | 04-12-2006 09:12 AM |
| Help with shell script - Unix Gurus calling | ravred | Shell Programming and Scripting | 4 | 01-26-2006 04:20 AM |
| convert date in lilian format for shell (AIX) | chocolate | AIX | 2 | 11-09-2004 04:48 AM |