The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

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-27-2006 11:30 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 08: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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 02-01-2006
geomonap geomonap is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 9
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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0