For Programmers: Free Programming Magazines  


Home > Archive > AWK > January 2006 > Re: nth day of the year?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: nth day of the year?
Alan Linton

2006-01-10, 3:58 am

Gernot Frisch wrote:

> hi,
>
> how can I get the number of today in the year?
>
> e.g. 24-nov-2005 = 328
>


function dayofyear(y,m,d) {
return julian(y,m,d)-julian(y,1,1)+1
}

function julian (y,m,d,hr,min,sec, A,B,C,D,ymd) {
#convert a calendar date & time to a Julian date
#Ref. Practical Astronomy With Your Calculator, 3rd Edition
#by Peter Duffett-Smith
#julian(-4712,1,1,12)==0; 4713 BC January 1, mid-day
#julian(1985,2,17,6)== 2446113.75000000
#julian(1990,0,0)==julian(1989,12,31)==2
447891.5

d = d + (hr + (min + sec / 60) / 60) / 24
if (m < 1) m = 1
if (m < 3) {
y = y - 1
m = m + 12
}
ymd = sprintf("%d%02d%02d", y, m, d)
if (ymd >= 15821015) {
A = int(y / 100)
B = 2 - A + int(A / 4)
} else {
B = 0
}
if (y < 0) {
C = int((365.25 * y) - 0.75)
} else {
C = int(365.25 * y)
}
D = int(30.6001 * (m + 1))
return sprintf("%f", B + C + D + d + 1720994.5)

}

This script does not depend on gawk or unix features.

Hope this helps,
Alan Linton
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com