function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ssousanssousan 

Apex julian date function

Is there a julian date function in APEX,

 

For example today [May 28 2013] has the julian date 2456441

 

Thanks

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Sean TanSean Tan

Does this work for you?

 

public static Integer getJulianDate(Date theDate)
{
    Integer y = theDate.year();
    Integer j = theDate.month();
    Integer k = theDate.day();
    
    return ( K-32075+1461*(I+4800+(J-14)/12)/4+367*(J-2-(J-14)/12*12) /12-3*((I+4900+(J-14)/12)/100)/4 );
}

 Formula taken from here:

 

http://aa.usno.navy.mil/faq/docs/JD_Formula.php

 

Comparing it against a online converter it's pretty accurate (though the converter has decimal points in it).

All Answers

ssousanssousan
Not really,
Sean TanSean Tan

Does this work for you?

 

public static Integer getJulianDate(Date theDate)
{
    Integer y = theDate.year();
    Integer j = theDate.month();
    Integer k = theDate.day();
    
    return ( K-32075+1461*(I+4800+(J-14)/12)/4+367*(J-2-(J-14)/12*12) /12-3*((I+4900+(J-14)/12)/100)/4 );
}

 Formula taken from here:

 

http://aa.usno.navy.mil/faq/docs/JD_Formula.php

 

Comparing it against a online converter it's pretty accurate (though the converter has decimal points in it).

This was selected as the best answer
ssousanssousan

Perfect,

 

Just an adjustment

 

public static Integer getJulianDate(integer I,integer J,integer K){   

 

   //  I= YEAR
   // J= MONTH
   //  K= DAY
         
  return ( K-32075+1461*(I+4800+(J-14)/12)/4+367*(J-2-(J-14)/12*12) /12-3*((I+4900+(J-14)/12)/100)/4 );
  }

 

I is not defined.