Function for Returning a Julian Date in FoxPro

This article was previously published under Q106690
This article has been archived. It is offered "as is" and will no longer be updated.
The FoxPro functions SYS(1) and SYS(11) return a Julian day number, whichis different from a Julian date. To return a Julian date, you can write auser-defined function (UDF), as described below.
SYS(1) and SYS(11) return a date according to the Julian calendar, in whicheach day is counted, with day 1 being in 4713 B.C. On the other hand, aJulian date is a date represented by a five-digit number, the first twodigits being the last two digits of the year, and the final three digitsbeing the number of days that have elapsed since January 1 of that year.For example, 01/01/93 according to the Julian calendar is 2448989, whereasthe Julian date is 93001.

The following program calls a UDF that converts a date in FoxPro dateformat to a Julian date.
   * Begin program   @1,1 SAY "Enter a date" GET testdate DEFAULT {  /  /  }   READ   @2,1 SAY "The Julian Date of "+ DTOC(testdate) + " is " ;      + TRANSFORM(julian(testdate),'99999')   *End program   FUNCTION julian   PARAMETER tdate   *isolate the year and convert it to a string   cYear = RIGHT(DTOC(tdate),2)   firstjan = CTOD("01/01/" + cYear)   *calculate the sequential number of the day   jday = tdate-firstjan+1   *position the year at the two leftmost digits   nYear = VAL(cYear) * 1000   *combine year and day number   jdate = nYear + jday   RETURN jdate   *End Function julian				
VFoxWin FoxDos FoxWin format

Article ID: 106690 - Last Review: 02/28/2014 04:15:15 - Revision: 2.1

Microsoft Visual FoxPro 3.0 Standard Edition, Microsoft FoxPro 2.0, Microsoft FoxPro 2.5b for MS-DOS, Microsoft FoxPro 2.5a, Microsoft FoxPro 2.5b for MS-DOS, Microsoft FoxPro 2.5b, Microsoft FoxPro 2.5a, Microsoft FoxPro 2.5b

  • kbnosurvey kbarchive kbcode KB106690