retitle 6485 Days Between Dates? How? thanks upload amritsar wrote: > can you plese tell me what is the procedure or command to find the days > between two date
If you would be so kind could you in the future address these types of questions to [email protected] instead of bug-coreutils? The bug-coreutils address has been changed from "all-discussion" to "bug-discussion" and along with that change every message here now opens a bug ticket in the bug tracking system so that we don't lose track of reported bugs. The [email protected] address was created for general discussion that isn't attached to the bug tracking system. Thanks! > supoose we have 2 date first one 01-01-2008 second one 21-06-2010 then > how can we calculate days between these two date . GNU date itself doesn't include any direct support for finding days between dates. But it can be used as part of a script to find this information. The technique is to convert each date to an integer value such as a Julian Day Number or seconds of the Unix epoch and then do take the difference and convert back. I will use Unix seconds in an example. Plus the date must be in a format that can be parsed by GNU date. date1="2008-01-01" date2="2010-06-21" date1seconds=$(date -d "$date1 12:00" +%s) date2seconds=$(date -d "$date2 12:00" +%s) totalseconds=$(( $date2seconds - $date1seconds)) secondsperday=86400 days=$(( $totalseconds / $secondsperday )) echo "There were $days days between $date1 and $date2" And of course that can be shorted up considerably by applying the constructs inline but I wanted to make things as illustrative as possible and so expanded them out. $ echo Days between dates: $(( ( $(date -d "2010-06-21 12:00" +%s) - $(date -d "2008-01-01 12:00" +%s) ) / 86400 )) I find it is often best to do date calculations using 12:00 noon so as to avoid any daylight savings time issues. > "The information contained in this electronic message and any > attachments to this message are intended for exclusive use of the > addressee(s) and may contain confidential or privileged > information. If you are not the intended recipient, please notify > the sender at LIC OF INDIA or [email protected] immediately > and destroy all copies of this message and any attachments. The > views expressed in this E-mail message / Attachments, are those of > the individual sender." Please don't post questions to public mailing lists with such a disclaimer attached to it. They are worthless and completely unenforceable but annoy many of us greatly. Please see this reference. http://goldmark.org/jeff/stupid-disclaimers/ If you cannot avoid such a disclaimer being attached to your email because your company does it to you automatically then please do not send mail from your company email account. Instead please sign up for and use one of the many free email accounts that are readily available on the Internet when corresponding with the Internet community. They are free. They are available. Do it for the good of the community. Bob
