How to convert date format such as 7/18/2015 to the number of month from request date in sh scripting ?

Let say I have output in my log.txt -> 7/18/2015. How I convert it to the full number of month in shell scripting ? Thanks in advance.

- 10-08-2012amerabestHow to convert date format such as 7/18/2015 to the number of month?
How to convert date format such as 7/18/2015 to the number of month from request date in sh scripting ?

Let say I have output in my log.txt -> 7/18/2015. How I convert it to the full number of month in shell scripting ? Thanks in advance. - 10-09-2012cnamejj
If your system supports the "--date" flag for passing a time into the "date" command, this should work to convert m/d/yyyy to seconds since 1/1/1970. You can do "time math" from there and convert back to date formats later if necessary.

Code:`date --date '7/18/2015' +"%s"`

- 10-09-2012amerabest
Hmm...interesting. Thanks. Good to know :)

But a little bit complicated in my case, since some month has 28-29-30-31 days. Any other solution how to count number of month from 'date' till 7/18/2015? - 10-09-2012cnamejj
Sorry, I misunderstood what you were trying to do. Actually I still don't know what you mean since a "month" isn't a fixed amount of time. So what does the number of months from an arbitrary date to 7/18/2015 mean? Unless the starting date is also the 18th day of a month it's going to be a fraction of a "month" even with a fuzzy definition of that unit.

If you can explain what you're trying to do a bit more I can probably come up with a suggestion.