View Single Post
  #6 (permalink)  
Old 11-19-09, 05:17
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Since your date does not support the -d flag try this ksh script to calculate ordinal date
Code:
#!/bin/ksh
dt=$1       # date as ccyy-mm-dd
calcord()   # function to calculate ordinal date
{
y=$1 m=$2 d=$3
set -A odm 0 0 31 59 90 120 151 181 212 243 273 304 334
echo ${y#??}$(( (m+9)/12*(y/4-(y-1)/4-y/100+(y-1)/100+y/400-(y-1)/400)+odm[m]+d )) # 2 digit year
#echo $y$(( (m+9)/12*(y/4-(y-1)/4-y/100+(y-1)/100+y/400-(y-1)/400)+odm[m]+d ))     # 4 digit year
}
oIFS=$IFS   # save Internal field separators
IFS='-'     # set Internal field separator
calcord $dt # do the calc
IFS=$oIFS   # restore Internal field separators
Note: all calculations are integer calculations i.e. 5/3=1

Last edited by pdreyer; 11-19-09 at 05:28. Reason: Note: integer calc
Reply With Quote