[jawsscripts] function for converting gregorian dates to a julian date

  • From: "John Martyn" <johnrobertmartyn@xxxxxxxxx>
  • To: <jawsscripts@xxxxxxxxxxxxx>
  • Date: Sat, 24 Mar 2012 09:33:01 -0700

I thought this would be another helpful item to have. Basically I want to
compare the elapsed dates of two Gregorian sytle dates formatted MM/dd/yyyy.
Here's a little function that turns it into a day number you can compare. I
took this from a PHP example, but it works just as well in JAWS script.
I wanted to examine the current date minus 30 days. Heres what I compare
with:
Var
Variant sysDate,
Int jDate
let sysDate = GTJ(SysGetDate ("MM/dd/yyyy"))
let jDate = StringToInt (sysDate)-30
function GTJ(string theDate)
var int m,
int y,
int c,
int d,
int j,
int ya
let m = StringToInt (StringSegment (theDate, "/", 1))
let y = StringToInt (StringSegment (theDate, "/", 3))
let d = StringToInt (StringSegment (theDate, "/", 2))
let c = StringToInt (StringLeft (StringSegment (theDate, "/", 3), 2))
let ya = StringToInt (StringRight (StringSegment (theDate, "/", 3), 2))
if m > 2 then
m = m - 3
else
m = m + 9
y = y - 1
endif
let c = y / 100
let ya = y - 100 * c 
let j = (146097 * c) / 4 + (1461 * ya) / 4 + (153 * m + 2) / 5 + d + 1721119
return j
/*      
Variables (all variables and results are integers):
        y = year (eg. 1999);
  m = month;  
d = day;  
c = century part of year (eg. 19);
        ya = decade part of year (eg. 99); 
j = Julian Day Number           
*/
EndFunction

__________�

View the list's information and change your settings at 
//www.freelists.org/list/jawsscripts

Other related posts:

  • » [jawsscripts] function for converting gregorian dates to a julian date - John Martyn