Computes the Gregorian day of the year from a serial Julian date.

You're viewing an older version of this page (#197). View the current version.

View versions (1)

Interface

#include <codecogs/units/date/dayofyear.h>

using namespace Units::Date;

This function calculates the day of the year from a serial date, such that 1st January = 1 and 31st December = 365 or 366 in a leap year. The Gregorian calendar is assumed for these calculations. The most general solution for our Julian mode is:

a = (nDate + 31738)\ mod\ 146097\ mod\ 36524\ mod\ 1461
(1)
b = a/1460
(2)
DayOfYear = (a-b)\ mod\ 365 + b + 1
(3)

where nDate is equal to the Julian Period, and all division are integer divisions.

Example 1

#include <stdio.h>
#include <codecogs/units/date/dayofyear.h>
#include <codecogs/units/date/date.h>
using namespace Units::Date;

int main()
{
  for(int i=5;i<15;i++)
  {
    int adate=date(2004, 2, i);
    printf("\n %d February 2004 is %d day of year", i, dayOfYear(adate));
  }
  return 0;
}

Parameters

nDate
is a serial number of days from 24 November 4714 BC (1 January 4713BC in the Julian Calendar) - also known as the Julian Period.
GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

nDate
Result