INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

last day of a month

last day of a month

(OP)
hello,
with the date command on a linux I can obtain last day of the current month:

$ date +%e -d "-$(date +%d) day"
30

How to modify the command to get with the command any month's last day?

I tried this but it return wrong value...

$ date +%e -d "02/02/2016 -$(date +%d -d "02/02/2016") day"
31

RE: last day of a month

(OP)

I get some results with this:

CODE --> date

$ date +%e -d "+1 month -$(date +%d) days"
31
$ date +%e -d "02/02/2016 +1 month -$(date +%d -d"02/02/2016") days"
29
$ date +%e -d "02/02/2015 +1 month -$(date +%d -d"02/02/2015") days"
28
$ date +%e -d "02/02/2014 +1 month -$(date +%d -d"02/02/2014") days"
28
$ date +%e -d "02/02/2013 +1 month -$(date +%d -d"02/02/2013") days"
28
$ date +%e -d "02/02/2012 +1 month -$(date +%d -d"02/02/2012") days"
29
$ date +%e -d "07/02/2012 +1 month -$(date +%d -d"07/02/2012") days"
31
$ date +%e -d "08/02/2012 +1 month -$(date +%d -d"08/02/2012") days"
31
$ date +%e -d "09/02/2012 +1 month -$(date +%d -d"09/02/2012") days"
30
$ date +%e -d "06/02/2012 +1 month -$(date +%d -d"06/02/2012") days"
30
$ 

RE: last day of a month

Hi

Kind of cheating, but may I suggest an alternative ?

CODE --> command line

master # cal | awk 'NF{l=$NF}END{print l}'
31

master # cal 2 2015 | awk 'NF{l=$NF}END{print l}'
28 

Regarding your date-based solution, I would also calculate that way.

Feherke.
feherke.ga

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close