Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date convert to days

Status
Not open for further replies.

nguyenb9

Technical User
Apr 1, 2003
55
US
How do you convert the past date such as 01/01/2001 to current days.

Thanks,
Bao
 
Hi:

Take a look at this thread over in the unix scripting thread:

thread822-514837

Regards,

Ed
 
Sorry! that is not what I am looking for. I am looking for the date that can convert it to how many days. For example from 12/29/2002 to 04/21/2003 is 113 days.

thanks
 
Hi:

Let's take a closer look (this is ksh):

JD1229=$(get_JD 29 12 2002) # Julian date 12/29/2002
JD0421=$(get_JD 21 4 2003) # Julian date 4/21/2003
diff=$((JD0421-JD1229))
echo $diff # should be 113

Regards,


Ed
 
I put the script together, don't seem to work. Can you tell me what is wrong?

#!/bin/ksh
set -x
get_JD ()
{
typeset -i JDD
JD1229=$(get_JD 29 12 2002) # Julian date 12/29/2002
JD1229=$(get_JD 29 12 2002) # Julian date 12/29/2002
diff=$((JD0421-JD1229))
echo $diff # should be 113
}

thanks,
 
get_JD is a ksh function:

#!/bin/ksh

# The Julian date (JD) is a continuous count of days from 1 January 4713 BC.
# The following # algorithm is good from years 1801 to 2099
# See URL: for more information
get_JD ()
{
typeset -i JDD

JDD=$(($1-32075+1461*($3+4800+($2-14)/12)/4+367*($2-2-($2-14)/12*12)/12-3*(($3+4
900+($2-14)/12)/100)/4))
echo $JDD
} # end get_JD

JD1229=$(get_JD 29 12 2002) # Julian date 12/29/2002
JD0421=$(get_JD 21 4 2003) # Julian date 4/21/2003
diff=$((JD0421-JD1229))
echo $diff # should be 113
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top