You are here

function date_calc_days_to_date in Date 6.2

Same name and namespace in other branches
  1. 5.2 date_php4/date_php4_calc.inc \date_calc_days_to_date()
  2. 6 date_php4/date_php4_calc.inc \date_calc_days_to_date()

Converts number of days to a distant unspecified epoch

Parameters

int $days: The number of days since the date_calc epoch.

string $format: The string indicating how to format the output.

Return value

string The date in the desired format.

12 calls to date_calc_days_to_date()
date_calc_begin_of_next_week in date_php4/date_php4_calc.inc
Find the month day of the beginning of week after given date, using variable_get('date_first_day', 1). Can return weekday of next month.
date_calc_begin_of_prev_week in date_php4/date_php4_calc.inc
Find the month day of the beginning of week before given date, using variable_get('date_first_day', 1). Can return weekday of prev month.
date_calc_begin_of_week in date_php4/date_php4_calc.inc
Find the month day of the beginning of week for given date, using variable_get('date_first_day', 1). Can return weekday of prev month.
date_calc_end_of_week in date_php4/date_php4_calc.inc
Find the month day of the end of week for given date, using variable_get('date_first_day', 1). Can return weekday of following month.
date_calc_get_calendar_month in date_php4/date_php4_calc.inc
Return a set of arrays to construct a calendar month for the given date.

... See full list

File

date_php4/date_php4_calc.inc, line 232

Code

function date_calc_days_to_date($days, $format = DATE_CALC_FORMAT) {
  $days -= 1721119;
  $century = floor((4 * $days - 1) / 146097);
  $days = floor(4 * $days - 1 - 146097 * $century);
  $day = floor($days / 4);
  $year = floor((4 * $day + 3) / 1461);
  $day = floor(4 * $day + 3 - 1461 * $year);
  $day = floor(($day + 4) / 4);
  $month = floor((5 * $day - 3) / 153);
  $day = floor(5 * $day - 3 - 153 * $month);
  $day = floor(($day + 5) / 5);
  if ($month < 10) {
    $month += 3;
  }
  else {
    $month -= 9;
    if ($year++ == 99) {
      $year = 0;
      $century++;
    }
  }
  $century = date_pad($century);
  $year = date_pad($year);
  return date_calc_format($day, $month, $century . $year, $format);
}