needs to display month for previous day date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting needs to display month for previous day date
# 1  
Old 12-18-2008
needs to display month for previous day date

Hello,

I wanted to display the month for previous day date. Like, today date is 18-Nov-2008. So the previous date is 17-Nov-2008. The output should be November.

If the today date is 1-DEC-2008, then output should be NOVEMBER.
If the today date is 1-JAN-2008, then output should be DECEMBER.
If the today date is 31-DEC-2008 then output should be DECEMBER.

Here is the code i am having now.

export FILE_FORMAT=`date '+%B`
echo $FILE_FORMAT

it is working for the below scenario

If the today date is 1-DEC-2008, then output should be NOVEMBER.
If the today date is 1-JAN-2008, then output should be DECEMBER.

Any help is appreciated...
# 2  
Old 12-18-2008
Let's say your in Central Time zone.

Your timezone might be represented by
TZ=CST6CDT

You could get the prior day by doing
TZ=CST30CDT
(6 + 24 = 30)

So:
$ TZ=CST30CDT date +%B

Should give you yesterday.

Alternatively you can install GNU's date program which can do date arithmetic.
# 3  
Old 12-18-2008
If you are using ksh93
Code:
$ printf "%(%B)T" "yesterday"

# 4  
Old 12-23-2008
Thanks Murphy.

Cjcox, Let me test this on Jan 1st 2009 and see it is displaying December.

Currently it is displaying december.. But this is not a real test now.

xx=CST30CDT date +%B
echo $xx

Thank you again.
# 5  
Old 12-23-2008
Code:
date --d='1 days ago'  +%B

This is assuming GNU date.

You can test it like this:
Code:
# date -d "2008-01-01" --date='1 days ago' +%B
December

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

2. UNIX for Dummies Questions & Answers

Get the previous month from date

Hi All, I am using the below code to get the year and month from date: Below gives output like 201212. dt=`date '+%Y%m'` how do i get the previous month value(ie: subtract 1 from date) example output: dt=201211 Please help. :confused: (3 Replies)
Discussion started by: abhi_123
3 Replies

3. Programming

How to get First and Last day of previous month from trunc(sysdate)

Hi Guys, How to get First day of previous month and last day of previous month from trunc(sysdate) using SQL..? Thanks in advance. Br, pinpe (2 Replies)
Discussion started by: pinpe
2 Replies

4. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

5. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

6. UNIX for Dummies Questions & Answers

How to get the previous month by using `date`

Hello, I'm new to shell scripting. We've develop a script which will grep a file on the search criteria, MON (Jan/Feb/Mar/etc). But we should set this sript in cron which will run on every first day of the month. The problem I'm having is, when I run the script, it is displaying the contents of... (7 Replies)
Discussion started by: suneelj
7 Replies

7. Shell Programming and Scripting

Display month for Previous day

Hello - I have one question regarding the date. I wanted to display the month name for previous day. The output should be as follows... 5-Feb-09 => February 1-Feb-09 => January 28-Feb-09=> February Here is the code i am using to get the output.... date '+%m %d %Y' | { read MONTH DAY... (4 Replies)
Discussion started by: govindts
4 Replies

8. Shell Programming and Scripting

Help, I need to get the last date of previous month

Hi, I'm new with Unix, I'm trying to get a last day of previous month with this format: %b %d %Y (example: Feb 25 2008). Here is what I have so far. #!/bin/ksh cur_month=`date +%m` cur_year=`date +%Y` prev_month=$(($cur_month-1)) # Check to see if this is January if then ... (11 Replies)
Discussion started by: sirrtuan
11 Replies

9. Shell Programming and Scripting

last working day of previous month

Hi, I want a script(ksh) to see if today is the last working day(Mon-Fri) of the month. If it is the last working day I need to print current date, else I need the last working day of previous month. Thanks in advance. (1 Reply)
Discussion started by: rspk_praveen
1 Replies

10. Shell Programming and Scripting

How to find the first day of previous month in unix?

How to find the first day of previous month in unix mmddyyyy format? example : today is 07052007 (in mmddyyyy) output sud be 06012007 thanks mohapatra (10 Replies)
Discussion started by: mohapatra
10 Replies
Login or Register to Ask a Question