how to get month last date in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to get month last date in unix
# 1  
Old 09-29-2005
how to get month last date in unix

Hello

I want to get end date of the any month in unix . is there any function to do this.


we can get month from date command 'date +%b'
example:

If Feb month then last date is 28

if sep then last date 30. like this


thanks

please help
This User Gave Thanks to rajan_ka1 For This Post:
# 2  
Old 09-29-2005
Try this command
You can include this in a shell script to get the month and year to pass to the below command.

cal 10 05 | grep -v ^$ | tail -1 | sed 's/^.* \([0-9]*\)$/\1/'

Last edited by monsanbu; 09-29-2005 at 06:39 AM..
# 3  
Old 09-29-2005
try this,

cal <month> <year> | sed '/^$/d' | tail -1 | awk '{printf $NF}'
# 4  
Old 09-29-2005
no use

not working

please check once again.

thanks
# 5  
Old 09-29-2005
Why dont you use the datecalc.

It does exactly what you require.
# 6  
Old 09-29-2005
Which solution is not working? Give the last two digits for year
# 7  
Old 09-29-2005
Code:
echo $(cal 10 2005) | awk '{print $NF}'

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

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

4. UNIX for Dummies Questions & Answers

Subtracting A month from an arbitrary date in UNIX

Hi, Is there a way to subtract a month or at least 30 days from an arbitrary or user inputted date without the GNU date? Example: please Input date: 2011-05-11 then the answer will be 2011-04-11 This code doesn't work: $date -d "2011-05-11 - 1 month" "+%Y%m%d" Thanks (7 Replies)
Discussion started by: erin00
7 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. AIX

Get Next month in AIX from curent date in unix AIX

How could we derive teh Next month in MON-RR format from current date ie sysdate in UNI AIX sheel script.I coould get a command but i supports only inLinux susse andnotin AIX. I need for Unix AIX.Pls Help. Regards Shiv (2 Replies)
Discussion started by: SHIV75
2 Replies

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

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

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

10. UNIX for Dummies Questions & Answers

How do I set my date in a unix script to 'new month

Hi, I'm a newbie to unix and i'm loving every bit of it. I need assistance in setting my date function in my script to "new month". What I want to do is define the "newmonth" as the 1st of every month so my script can run by this time evry month through the year. Can someone assist. ... (1 Reply)
Discussion started by: Agent704
1 Replies
Login or Register to Ask a Question