-1

I would like to convert a date such as 2014/09/30 to a Julian date. Converting a date should return an integer.

The reason why I want this integer is to use it in a subtract formula, and then revert the final results back to a date.

How can I convert a date to a Julian and then convert the final results to a date?

admdrew
  • 3,790
  • 4
  • 27
  • 39
AJR
  • 569
  • 3
  • 12
  • 30
  • Thanks, i was able to use the following code: Date.prototype.getJulian = function() { return Math.ceil((this / 86400000) - (this.getTimezoneOffset()/1440) + 2440587.5); } var valDate = input1[0]; var dt = new Date(valDate); var julian_dt = dt.getJulian(); output1 = julian_dt; – AJR Oct 14 '14 at 20:41
  • Is there an example on how to do the reverse ... convert a julian to a regular date in this format "2014/09/30" ?? – AJR Oct 14 '14 at 20:54

2 Answers2

2
Date.prototype.getJulian = function() {
  return Math.ceil((this / 86400000) - (this.getTimezoneOffset()/1440) + 2440587.5);
}

var valDate = input1[0];
var dt = new Date(valDate);
var julian_dt = dt.getJulian();

output1 = julian_dt;

i was able to use the code above.

Thanks

AJR
  • 569
  • 3
  • 12
  • 30
0

You should get familiar with javascript's Date objects. You can subtract one date object from another to find differences in time, and all kinds of other nifty things. It's definitely much cleaner, and less error-prone, than working with strings and integers.

Raphael Serota
  • 2,157
  • 10
  • 17