I am trying to find out the number of days between the current date and user defined date.
I took reference from here for the date2jd() function.
Modified the function according to my requirement. But its not working properly.
Original code from here is working fine.
#!/bin/sh
########### date2jd function ############
date2jd() {
integer ijd day month year mnjd jd lday
year=$1
month=$2
day=$3
echo $year
echo $month
echo $day
((standard_jd = day - 32075
+ 1461 * (year + 4800 - (14 - month)/12)/4
+ 367 * (month - 2 + (14 - month)/12*12)/12
- 3 * ((year + 4900 - (14 - month)/12)/100)/4))
((jd = standard_jd-2400001))
echo $jd
return 0
}
########### user defined date ###########
echo 'Enter date in the format dd/mm/yyyy'
read DATE
DD=`echo $DATE | cut -c1-2`
MM=`echo $DATE | cut -c4-5`
YYYY=`echo $DATE | cut -c7-10`
####### current date ############
DD2=`date '+%d'`
MM2=`date '+%m'`
YYYY2=`date '+%Y'`
jd1=$(date2jd $YYYY1 $MM1 $DD1) || exit $?
jd2=$(date2jd $YYYY2 $MM2 $DD2) || exit $?
((jd3=jd2-jd1))
echo $jd3
Please help.