The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 04-22-2009
colemar colemar is offline
Registered User
  
 

Join Date: Apr 2009
Location: Trento, Italy
Posts: 116
Quote:
Originally Posted by jidsh View Post
I need to validate that difference between the two dates is always less than or equal to 60 days.
If using the external command date is not against the rules, and provided that you are using date from GNU Coreutil then:

Code:
colemar@deb:~$ cat days_between
#!/bin/sh

typeset -i days_between
function days_between {
  days_between=$((($(date -d $2 +%s)-$(date -d $1 +%s))/86400))
}

days_between $1 $2
echo $days_between

colemar@deb:~$ ./days_between 2008-04-22 2009-04-22
365