Seeking help with date calculations in bash (on MacOS-X)
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
As you can see, the script expects a date in the dd-mmm-yyyy format, so it calculates time elapsed till the beginning of the specified day; for example, time elapsed from 26-Sep-2013, 00:00, till the time I am typing this is:
With some modifications, the script can do much more things, such as automatically calculating the time till next Christmas, or the time till your next birthday, but I'll leave that as an exercise to the reader
is what i must create file.sh is the script writed by me and when user is run it with some parameter i must have the result for nomather which will be the parameter for now i have this
y must compare with the actual date to find the age
Date formats are different for different regions of the planet.
Is that expected input always supposed to be MM-DD-YYYY? (05-12-1993)
That may be taken as Dec 12, 1993 in Europe...I think.(I'm an American m-d-y is the 'norm' here.)
You may wish to advise the user of the expected input format (echo "Please use MM-DD-YYYY as the format")
Search MINPARAMS here...
some hints for "date math"
date +"%m-%d-%Y" --date="+6 months +29 days"
date +"%m-%d-%Y" --date="+365 days"
date +"%m-%d-%Y" --date="+364 days"
date +"%m-%d-%Y" --date="+11 months 26 days"
That should keep you from scratching your eyes out.