cancel
Showing results for 
Search instead for 
Did you mean: 

Julian Date and Day

Former Member
0 Kudos

Hi,

I need my filename to be created based on Julian Date or Julian Day.  I have a field in mapping which can be used for this.

I am struggling whether the currentdate function offers Julian Date or Day. 

Please let me know if any one has done a requirement like that.

Regards

Anandh.B

Accepted Solutions (1)

Accepted Solutions (1)

former_member184681
Active Contributor
0 Kudos

Hi,

This can be done with the following UDF:

  Calendar calendar1 = Calendar.getInstance();

  Calendar calendar2 = Calendar.getInstance();

  calendar1.set(1, 0, 1); //leave this unchanged

  calendar2.set(2012, 3, 27); //put your input date's year, month-1 (0 to 11 instaed of 1-12) and day

  long milliseconds1 = calendar1.getTimeInMillis();

  long milliseconds2 = calendar2.getTimeInMillis();

  long diff = milliseconds2 - milliseconds1;

  long diffDays = diff / (24 * 60 * 60 * 1000);

  diffDays += 1721423;

  return diffDays;

Hope this helps,

Greg

Answers (3)

Answers (3)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Anandh.B,

                  

The Julian date (JD) is the interval of time in days and fractions of a day since January 1, 4713 BC Greenwich noon, Julian proleptic calendar. The Julian day number (JDN) is the integer part of the Julian date (JD).The day commencing at the above-mentioned epoch is JDN 0. Now, at 12:39, Sunday April 29, 2012 (UTC) the Julian day number is 2456047. Negative values can be used for dates preceding JD 0, though they predate all recorded history. However, in this case, the JDN is the greatest integer not greater than the Julian date rather than simply the integer part of the JD. Please consult this link for formula to obtain julian date

http://scienceworld.wolfram.com/astronomy/JulianDate.html

and the following to test the output of UDF shown below

http://aa.usno.navy.mil/data/docs/JulianDate.php

the UDF is as shown below

public String currentDateToJulianDate(Container container){

String julianDate="";

  try

  {

   java.util.Calendar cal = new java.util.GregorianCalendar();

   double hour24 = cal.get(java.util.Calendar.HOUR_OF_DAY);     // 0..23

   double min = cal.get(java.util.Calendar.MINUTE);   //0..59

   double sec=cal.get(java.util.Calendar.SECOND);

   int day=cal.get(java.util.Calendar.DAY_OF_MONTH);

   int month=cal.get(java.util.Calendar.MONTH)+1;

   int year=cal.get(java.util.Calendar.YEAR);

   double jd=0.0;

   jd=(367*year)-(int)(7*(year+(int)((month+9)/12))/4)

    -(int)((3*(int)((year+(month-9)/7)/100)+1)/4)

    + (int)((275*month)/9)+day+1721028.5

    +(hour24+(min/60)+(sec/3600))/24;

     julianDate=""+jd;

  }

  catch(Exception e)

  {

   e.printStackTrace();

  }

  return julianDate;

}

This UDF converts current date and time to julian date.

Hope this resolves your problem.

Regards

Anupam

iaki_vila
Active Contributor
0 Kudos

HI AnandhaKrishnan,

I agree with Baskar.you should create an UDF to resolve this problem. Check this web with an example in java http://www.rgagnon.com/javadetails/java-0506.html

Regards

baskar_gopalakrishnan2
Active Contributor
0 Kudos

I don't think standard date functions support julian date. You might have to write UDF to implement this.