How to show last month date?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to show last month date?
# 1  
Old 08-05-2011
How to show last month date?

Hi Guys,

Please somebody give me a hand to show the Month & Year in assigning to a variable and with format "MMMYY" (i.e. Jul11). See below preferred output.

I tried using this but it is giving me the current month...
Code:
date = "`date +%b%y`"
Aug11


DESIRED OUTPUT:
Code:
Jul11


Thank in advance.


Br,
pinpe
# 2  
Old 08-05-2011
with GNU date
Code:
$ date --date '1 month ago' '+%b%d'
Jul05
$
$ date --date '1 month ago' '+%b%y'
Jul11
$

# 3  
Old 08-05-2011
Quote:
Originally Posted by anchal_khare
with GNU date
Code:
$ date --date '1 month ago' '+%b%d'
Jul05
$

Hi anchal_khare,

Thanks for the reply but I'm using UNIX OS. The command you gave me is giving me errors as shown below...

Code:
root@hostname>date --date '1 month ago' '+%b%d'
date: illegal option -- date
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]


Br,
pinpe
# 4  
Old 08-05-2011
Well in that case, you should have a look at the FAQS section. lots of date calculations related threads are available with solutions.

also look at the Perderabos datecalc
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How bash treats literal date value and retrieve year, month and date?

Hi, I am trying to add few (say 3 days) to sysdate using - date -d '+ 3 days' +%y%m%d and it works as expected. But how to add few (say 3 days) to a literal date value and how bash treats a literal value as a date. Can we say just like in ORACLE TO_DATE that my given literal date value... (2 Replies)
Discussion started by: pointers1234
2 Replies

2. Shell Programming and Scripting

Not able to fetch previous month first date and last date

I am not able to fetch first date and last date previous month date -d -1month +%Y-%m-%d date -d -1month +%Y-%m-%d I need two format dd-mm-yyy previous month 01-03-2016 previous month 31-03-2016 and also only date 1 to 31 Aprriciate your replay (4 Replies)
Discussion started by: jagu
4 Replies

3. Shell Programming and Scripting

Find one month before date

Hi, I want two dates one will be the current date and the other one will be just one month before. Say if current month is 11/4/2014 then the other date should be 11/3/2014. #!/bin/ksh currentDtae=`date` oneMonthBefore= ? I dont know how to do it. Went through some of the related threads... (15 Replies)
Discussion started by: Sharma331
15 Replies

4. Shell Programming and Scripting

How to list files that are not first two files date & last file date for every month-year?

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (2 Replies)
Discussion started by: Makarand Dodmis
2 Replies

5. 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

6. 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

7. Shell Programming and Scripting

Pass the first date and last date of previous month

Hi All, I need to run a job every month at the beginning of the month which is scheduled through autosys, lets say on 03/01/2010. I need to pass the last month's i.e February's first_date = 02/01/2010 and last_date = 02/28/2010 as variables to a stored procedure. Can somebody please pass... (2 Replies)
Discussion started by: vigdmab
2 Replies

8. 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

9. UNIX for Dummies Questions & Answers

ls how to not show date

Hello, I'm using ls -laR to print out a list of file and folders. I want to print only the permission, file size and file name. Also, excluding the '.' and '..'. result from ls -laR: total 6 drwxr-xr-x 8 user staff 512 Nov 28 16:17 . drwxr-x--- 16 user staff 1024... (3 Replies)
Discussion started by: minifish
3 Replies

10. Shell Programming and Scripting

yesterday date month/date

Hi expert, I want to retrieve yesterday su log. How to calculate and assign variable value ( 06/23 ) in myVariable ? #!/bin/sh myVariable=yesterday date in month/date cat /var/adm/sulog | grep $myVariable > file.txt many thanks! (5 Replies)
Discussion started by: skully
5 Replies
Login or Register to Ask a Question