No announcement yet.

How do you convert a Date to Julian Date

  • Filter
  • Time
  • Show
Clear All
new posts

    How do you convert a Date to Julian Date

    I need to do some calculations with dates (adding and subtracting days mostly). I can do this in tradestation by using a function they call DateToJulian(). I then do my calculations and convert the result back using the inverse function, you guessed it JulianToDate()! (See below for definitions)

    Now that I am converting all my code to PB i have to write these two functions. But short of a lookup table and some kind of compenstion for leap years I cant think of slick way to do it.

    Are there any Win API calls that might do this?

    DateToJulian Function:

    Returns the Julian date for the specified calendar date.

    DateToJulian(cDate) ;

    (cDate) is a numeric expression representing the date in the format YYYYMMDD


    If a specific date is entered for the numeric expression, it must be a valid date between January 1, 1901 and February 28, 2150


    DateToJulian(980804) returns a value of 36011 for the date August 4, 1998.

    DateToJulian(991024) returns a value of 36457 for the date October 24, 1999
    JulianToDate Function:

    Returns the calendar date for the specified Julian date.

    JulianToDate(jDate) ;
    (jDate) is a numeric expression representing the Julian date.


    JulianToDate(36011) returns a value of 19980804 for the date August 4, 1998.

    JulianToDate(36457) returns a value of 19991024 for the date October 24, 1999.

    Kind Regards

    there are a bunch of julian date functions in the source code forum... a quick search for "julian" reveals at least three postings. there may be more in the srccode archive forum too.

    for example:

    powerbasic support
    mailto:[email protected][email protected]</a>
    mailto:[email protected]


      You might also investigate the Windows API SystemTime & FileTime
      structures and their related functions (FileTimeToSystemTime,
      SystemTimeToFileTime, etc.)

      The FileTime structure is really just a QUAD value which is similar
      to a Julian, but not exactly the same. You can perform math on the
      dates with it, however.

      Bernard Ertl
      Bernard Ertl
      InterPlan Systems