Date Logic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date Logic
# 1  
Old 03-01-2004
Date Logic

If I do a date + "%b%Y" I get Mar2004. How do I then get unix to tell me that the previous month and year is Feb2004? The logic will also have to work for Jan2005 and Dec2004. Thanks..
# 2  
Old 03-01-2004
1) dont use the Alphabetical version of the month.
1a) use a case statement to translate the numercial month to a Alphabetical version if that is your requirement.

2) use a case statement.

by useing the numerical number vs. alphabet you can do simple math to get the previous month.
# 3  
Old 03-01-2004
It depends on what system you're on. For example, GNU date (installed on Linux boxes) will allow this:
Code:
date --date="1 month ago" +%b%Y

If it's worth it, and possible, (in some cases it may be both), you can head over to GNU.org and download GNU "sh-utils" package.

Another way to do so (which I've used on systems I am not allowed to install new binaries on), is this wonderful tool, written by Perderabo:
https://www.unix.com/showthread.php?s...6559#post16559
# 4  
Old 03-09-2004
If you have an RDBMS like Informix, Oracle or MySql installed you might consider using that to perform the date calculations for you.

In a script:

1. Create a 'temporary' table with a date type column
2. Populate the date column with an insert statement.
3. Perform the calculation with a select statement. e.g.
select (mydate -1)
from tt_calc
4. Drop the table once you have finished with it.

All of the above actions can certainly be scripted using Shell Script and Informix. The return value of step 3 can be captured into a shell variable. The format returned will depend on your RDBMS and how it is configured.

Hope this helps.

MBB
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date increment logic

Hi all, I need to increment date at run time. Example: I need to write a shell script with two parameters. 1. country code like (US,UK, IND.....) 2. Date range from_date to to_date (20070101 to 20070331) I need to run shell script like this country_info.sh US 20070101 20070331 ... (3 Replies)
Discussion started by: pmreddy
3 Replies

2. Shell Programming and Scripting

Logic for file fetching based on date

Dear friends, I receive the following files into a FTP location on a daily basis -rw-r----- 1 guest ftp1 5021 Aug 19 09:03 CHECK_TEST_Extracts_20080818210000.zip -rw-r----- 1 guest ftp1 2437 Aug 20 05:15 CHECK_TEST_Extracts_20080819210000.zip -rw-r----- 1 guest ... (2 Replies)
Discussion started by: sureshg_sampat
2 Replies
Login or Register to Ask a Question