Get number of days between given dates

Hi

I need one single command to get number of days between
two given dates.datecalc is not working.

ex.
fromdate:01.04.2010
todate :24.04.2010

i should get the out put as 23

Thanks in advance

With the datecalc script of Perderabo http://www.unix.com/unix-dummies-questions-answers/4870-days-elapsed-between-2-dates.html\#post16559 you should get the desired output but the date must be reformatted:

#!/bin/sh

fromdate=01.04.2010
todate=24.04.2010

from=`echo $fromdate | awk  -F\. '{print $3 OFS $2 OFS $1}'`
to=`echo $todate | awk  -F\. '{print $3 OFS $2 OFS $1}'`

./datecalc -a $to - $from

Here is a slightly modified example based on the above.
First we reformat the date to YYYYMMDD format.
Then for each date we compute the number of seconds since 1970-01-01 00:00:00 UTC (parameter %s of the date function)
Finally the result is divided by 86400 (number of seconds in a day).

#!/bin/sh

fromdate=01.04.2010
todate=24.04.2010

from=`echo $fromdate | awk  -F\. '{print $3$2$1}'`
to=`echo $todate | awk  -F\. '{print $3$2$1}'`

START_DATE=`date --date=$from +"%s"`
END_DATE=`date --date=$to +"%s"`

DAYS=$((($END_DATE - $START_DATE) / 86400 ))
echo $DAYS

=> 23

--date is an option of the GNU date and is not portable.

Using ks93 printf properties:

#!/bin/ksh
isodate()
{      # dd.mm.yyyy to yyyy-mm-dd
        indate="$1"
        oifs="$IFS"
        IFS="."
        values=($indate)
        IFS="$oifs"
        iso="${values[2]}-${values[1]}-${values[0]}"
        echo "$iso"
}

fromdate=$(isodate 01.04.2010)
todate=$(isodate 24.04.2010)
# datestr => epoc
epoc1=$(printf "%(%#)T"   "$fromdate")
epoc2=$(printf "%(%#)T"   "$todate")

# length of day (seconds) = 86400
((day=24*60*60))
echo $(( (epoc2-epoc1) /day))

More datecalc examples in my answer, and all other answers