Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
echo "("$(date -d 2006-10-02 +%s)-$(date -d 2005-11-32 +%s)")/86400" | bc
303
#!/bin/ksh
# parameters
# days in year
yd=365
# days in leapyear
ld=366
# elapsed days before month x in non-leap year
mo[1]=0 mo[2]=31 mo[3]=59 mo[4]=90 mo[5]=120 mo[6]=151
mo[7]=181 mo[8]=212 mo[9]=243 mo[10]=273 mo[11]=304 mo[12]=334
# elapsed days before month x in leap year
ml[1]=0 ml[2]=31 ml[3]=60 ml[4]=91 ml[5]=121 ml[6]=152
ml[7]=182 ml[8]=213 ml[9]=244 ml[10]=274 ml[11]=305 ml[12]=335
# variables
date1=2003-03-01
date2=2004-03-01
leapyear()
{
# is year $1 a leapyear?
yr=$1
ly=0
if (( !(yr%4) ))
then
if (( !(yr%100) ))
then
if (( !(yr%400) ))
then
ly=1
fi
else
ly=1
fi
fi
echo ${ly}
}
julian()
{
# convert month, day to julian: day of the year
l=$1
m=$2
d=$3
if (( l==0 ))
then
((ju=mo[m]+d))
else
((ju=ml[m]+d))
fi
echo ${ju}
}
echo $date1|tr '-' ' '|read y1 m1 d1
l1=$(leapyear $y1)
j1=$(julian $l1 $m1 $d1)
echo $date2|tr '-' ' '|read y2 m2 d2
l2=$(leapyear $y2)
j2=$(julian $l2 $m2 $d2)
((diff=0))
if ((y1==y2))
then
((diff=j2-j1))
else
if ((y1<y2))
then
factor=1
else
# switch dates, negative diff
echo ${y1} ${m1} ${d1} ${l1} ${j1} ${y2} ${m2} ${d2} ${l2} ${j2}|read y2 m2 d2 l2 j2 y1 m1 d1 l1 j1
factor=-1
fi
# days until end of year of begin date
if ((l1==1))
then
((diff=ld-j1))
else
((diff=yd-j1))
fi
((y1+=1))
# keep adding yd or ld for every year or leapyear passed
while ((y1<y2))
do
l1=$(leapyear $y1)
if ((l1==1))
then
((diff+=ld))
else
((diff+=yd))
fi
((y1+=1))
done
# add julian date of end date
((diff+=j2))
# positive or negative difference?
((diff*=factor))
fi
echo "difference between ${date1} and ${date2} is ${diff} days"