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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
adding or subtracting days in the o/p of date St.Fartatric UNIX for Dummies Questions & Answers 1 05-19-2008 07:10 AM
Cron to run first day of month to calculate date 3 months ago new2ss Shell Programming and Scripting 1 05-17-2007 02:28 AM
Subtract 2 months from the date mahekr2000 UNIX for Advanced & Expert Users 5 07-23-2006 12:01 PM
Subtracting date / timestamps roadcyclist Shell Programming and Scripting 0 06-21-2006 02:51 PM
subtracting a days from current date rameshspal Shell Programming and Scripting 1 03-10-2006 01:18 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-05-2002
jwatson12 jwatson12 is offline
Registered User
  
 

Join Date: Aug 2002
Posts: 2
Subtracting Two months from date

Hello:

I am running a script that creates a database and renames the output file to append the current date in month-year format. However, I need to append the date with todays date minus two months. For example:

Aug2002 should read Jun2002.

Here is a copy of my current script:
Code:
---------------------------------------------------------------------------------
  #!/bin/sh


#Build cube
rsserver -c -m/global/site/vendor/cognos/Dealerops/models/historymodels/oduchistorydomclosmo.mdl -DLogFileName=/global/site/vendor/cognos/Dealerops/log/histcur.log -kODUCDB2U=cognos/songoc01

#Set Date Variable for appending date to file name (month-year format)
cogdate="`date +%h%Y`"
#Set Return Status variable
ret_stat=$?

#Check the return status of rsserver, if okay, do the necessary file transfers
# and update the cube on PPES and make mail subject "SUCCESS". 
# Otherwise, change mail subject to "FAILURE"
if test $ret_stat -eq 0 
then
subject="HistoryCubeBuild:SUCCESS"

cd /global/site/vendor/Dealerops/cubes
cp ODUCHISTDOMCUR.mdc /global/site/vendor/Dealerops/cubes/History/HISTCUR"$cogdate".mdc

else
subject="HistoryCubeBuild:FAILURE"
fi


MailToNames="XXXX.com" 
OutputFile=/global/site/vendor/Dealerops/log/histcur.log
cat $OutputFile | mailx -s $subject $MailToNames

exit $ret_stat
added code tags for readability --oombera

Last edited by oombera; 02-18-2004 at 01:12 PM..
  #2 (permalink)  
Old 09-05-2002
auswipe's Avatar
auswipe auswipe is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 535
Re: Subtracting Two months from date

Quote:
Originally posted by jwatson12
Hello:
I am running a script that creates a database and renames the output file to append the current date in month-year format. However, I need to append the date with todays date minus two months. For example:
Check with man for your version of date and see if it supports the -v switch.

Under FreeBSD, I was able to use

Code:
date -v -2m +%h%Y
Example:

Code:
FreeBSD:auswipe:/home/auswipe $ date
Thu Sep  5 13:37:22 CDT 2002
FreeBSD:auswipe:/home/auswipe $ date -v -2m
Fri Jul  5 13:37:28 CDT 2002
FreeBSD:auswipe:/home/auswipe $ date -v -2m +%h%Y
Jul2002
  #3 (permalink)  
Old 09-05-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
If you're using GNU date you can do this:
Code:
[...]
date --date="2 months ago" +%m%Y
[...]
If you're not using GNU date and would like to, you can get it at gnu.org, in the "sh-utils" package.
  #4 (permalink)  
Old 09-13-2002
jwatson12 jwatson12 is offline
Registered User
  
 

Join Date: Aug 2002
Posts: 2
Tool is not available. I am working in a production environment and cannot add utilities.

What this script is doing is calling an OLAP database kernel that generates financial numbers for a financial closing of two months prior to the system date. The filename must be in sync with the record dates in the database source.

Therefore, If System Month = Jan, then New Month = Nov, etc. Perhaps it is best to converrt the month to number. Any ideas or scripts someone can share?

Thanks,
Newbie
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 11:07 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