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
Help, I need to get the last date of previous month sirrtuan Shell Programming and Scripting 11 10-14-2008 05:59 AM
Get date one month from today frustrated1 Shell Programming and Scripting 5 08-15-2008 08:01 AM
yesterday date month/date skully Shell Programming and Scripting 5 06-24-2008 05:51 AM
last month end date vanathi UNIX for Advanced & Expert Users 7 03-21-2008 04:17 PM
how to get month last date in unix rajan_ka1 Shell Programming and Scripting 12 10-04-2005 07:20 AM

Closed Thread
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
  #1 (permalink)  
Old 02-10-2009
niceboykunal123 niceboykunal123 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 31
Substract date (month) Problem

#!/bin/ksh

month=`date | cut -c5-8`
year=`date | cut -c24-28`

echo "$month"
echo "$year"

--- This gives me output as Feb and 2009
but now I want to substract the 1 month from the current script and want output as

Jan 2009.


Please note I have searched a lot on forum and found option -v with date but it doesn't work wd on my mc.

Please help...!!!
  #2 (permalink)  
Old 02-10-2009
sunpraveen's Avatar
sunpraveen sunpraveen is offline
Registered User
  
 

Join Date: Jan 2009
Location: Pruthvi
Posts: 85
Kunal,

Check this link. You might find your answer.

Request you to go through the FAQ section and search for similar threads before creating a new one.

Regards,

Praveen
  #3 (permalink)  
Old 02-10-2009
niceboykunal123 niceboykunal123 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 31
Hi, praveen

as i said, date -v option not working from my end....

hence need help
  #4 (permalink)  
Old 02-10-2009
Whiteboard's Avatar
Whiteboard Whiteboard is offline
Registered User
  
 

Join Date: Feb 2009
Location: @........
Posts: 111
Try this

Code:

day=`date +%d`
month=`date +%m`
year=`date +%Y`
lmonth=`expr $month - 1`
if test "$lmonth" = "0"
then
lmonth=12
year=`expr $year - 1`
fi
echo "Last month was $lmonth/$year"
  #5 (permalink)  
Old 02-10-2009
sunpraveen's Avatar
sunpraveen sunpraveen is offline
Registered User
  
 

Join Date: Jan 2009
Location: Pruthvi
Posts: 85
try this option:

Code:

get_month_name() 
{
case $1 in
01) month_name="Jan"
02) month_name="Feb"
03) month_name="Mar"
04) month_name="Apr"
05) month_name="May"
06) month_name="Jun"
07) month_name="Jul"
08) month_name="Aug"
09) month_name="Sep"
10) month_name="Oct"
11) month_name="Nov"
12) month_name="Dec"
}

month=`date +%m`
year=`date +%Y`

month=$(( ${month} - 1 ))

if [[ ${month} -eq 0 ]]; then
month=12
year=$(( ${year} - 1 ))
fi
if [[ ${month} -lt 10 ]]; then # prefix a zero in front of
month=0${month}
fi
get_month_name "${month}"

echo ${month_name}${year}
HTH,

Regards,

Praveen
  #6 (permalink)  
Old 02-10-2009
niceboykunal123 niceboykunal123 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 31
Thanks a lot - Praveen....!!!

thanks again
Closed Thread

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 08:34 PM.


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