|
|
Q807 How can I subtract 12 months from a date in Julian form and decide whether to subtract 365 days or 366 days (when one of the months included in the 12 months is February and contains 29 days)?
irt.org | Knowledge Base | JavaScript | Date | Q807 [ previous next ] Q807 How can I subtract 12 months from a date in Julian form and decide whether to subtract 365 days or 366 days (when one of the months included in the 12 months is February and contains 29 days)?It depends what format your Julian date is in. If its the format: YYYYDDD then I would recommend converting this to a proper date: then checking to see if the date returned is the 29th of Feb, and if it is subtract 1 year and 1 day from the date instead of just 1 year. Assuming that your Julian date format contains embedded zeros, e.g. 1999048 for today's date the 17th of February 1999., then you can extract the date and number of days quite simply with:
This can then be used to create a date object for the relevant date:
Then you need to do is check that the date isn't the 29th of February:
A test script to demonstrate that this works for Leap Days is shown below:
|
-- div -->
|