heres a function set and test script for working to and from julian dates
that someone else may find useful.
Code:
/*
Available Functions:
gojulian(y,m,d,pd) - converts to julian
goconvertback(JD,pd) - converts from julian
DAYWEEK(JD,par) - gets day of week from julian
Julian date is best for adding days between dates or to find number days between dates
taken from fortran script, simplified as much as possible
use SetFormat, Float ,0.0 before calling
Dave Anderson 11/24/2007
V1.0
*/
;===== converts to julian date 5 digits or 7 digits ========
;===== y=year, m=month, d=day pd =1 for 5 digits, anything else 7 digits==============================
gojulian(y,m,d,pd)
{
if (m < 3) {
m += 12
y--
}
jdn:=-678972+d+((153*m-2)//5)+365*y+(y//4)-(y//100)+(y//400)
if (pd=1)
return , jdn
else
return, jdn+2400000
}
;==============convert from julian date ============================
;====JD= 5 or 7 digit julian date, pd =1 for yyyymmdd, 2 for MMM d, yyyy=
goconvertback(JD,pd)
{
if StrLen(JD)=7
JD-=2400000
A:=JD+2468569, C:=JD//36524+68, F:=(a-(((146097*C)+3)//4))
g:=(4000*(F+1)//1461001), L := F-(1461*g//4)+31
J := (80*L)//2447, D := L-(2447)*J//80, B := J//11
J := J+2-(12*B), Y := (100*(C-49))+g+B
sr=0%D%
StringRight ,D,sr,2
sr=0%j%
StringRight ,J,sr,2
if (pd=2)
{
M:=MONTH(J)
date=%M% %D%, %Y%
return , %date%
}
date=%Y%%J%%D%
return , %date%
}
MONTH(J)
{
Monstr=OOJanFebMarAprMayJunJulAugSepOctNovDec
StringMid, M,Monstr,J*3,3
RETURN , M
}
;============ returns 3 digit weekday ============
;par is 1 = numerical day (1-7), 2 = 3 digit Abreviation (Sun-Sat)
DAYWEEK(JD,par)
{
Daystr=OOSunMonTueWedThuFriSat
if StrLen(JD)=7
JD-=2400000
NDW:=mod(JD+2,7)+1
if (par=1)
{
StringMid, DW,Daystr,NDW*3,3
return, DW
}
RETURN , NDW
}
and the test script:
Code:
;SetFormat , Float,0.0
CYear=%A_YYYY% ;current 4 digit year 2007
CMonth=%A_MM% ;current 2 digit month ie 01
CDay=%A_DD% ;current 2 digit day ie 21
MsgBox , date being sent for conversion %CYear% %CMonth% %CDay%
;=============== get julian date in 5 digit version ===========
JDN:=gojulian(CYear,CMonth,CDay,1)
MsgBox , the julian date is %JDN%
;get Day of Week in 3 digit Abbreviation ie Mon from julian =========================
DWA:=DAYWEEK(JDN,1)
MsgBox , Day of Week Abbrev is %DWA%
;get day of week number 1-7 from julian ==============================================
DWN:=DAYWEEK(JDN,2)
MsgBox , Day of Week Number is %DWN%
JDN+=5 ; add 5 days ================================================================
;===================================convert from julian date starts here ============
;======================= sending JDN removing all right of decimal point ===========
; =========================dont need the time of day part of julian date ===========
Transform,JDNc,Round,JDN
MsgBox , Julian Date being converted %JDNc%
dateT:=goconvertback(JDNc,1) ; returns 8 digit date in YYYYMMDD format =============
MsgBox , 8 digit date = %dateT%
dateT:=goconvertback(JDNc,2) ; returns date in MMM d, yyyyy format
MsgBox , Month day, year = %dateT%
Exit
#Include, JulianFunctions.ahk
Hope someone finds it useful....