You are here

function date_calc_prev_day_of_week in Date 6

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

Returns date of the previous specific day of the week from the given date.

Parameters

int: Day of week, 0=Sunday.

int $day: The day of the month.

int $month: The month.

int $year: The 4 digit year. Do not add leading 0's for years prior to 1000.

bool $on_or_before: If true and days are same, returns current day.

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

Return value

string The date in the desired format.

1 string reference to 'date_calc_prev_day_of_week'
date_php4.inc in date_php4/date_php4.inc

File

date_php4/date_php4_calc.inc, line 986

Code

function date_calc_prev_day_of_week($dow, $day = 0, $month = 0, $year = 0, $format = DATE_CALC_FORMAT, $on_or_before = false) {
  if (empty($year)) {
    $year = date_calc_get_year();
  }
  if (empty($month)) {
    $month = date_calc_get_month();
  }
  if (empty($day)) {
    $day = date_calc_get_day();
  }
  $days = date_calc_date_to_days($day, $month, $year);
  $curr_weekday = date_dow($day, $month, $year);
  if ($curr_weekday == $dow) {
    if (!$on_or_before) {
      $days -= 7;
    }
  }
  elseif ($curr_weekday < $dow) {
    $days -= 7 - ($dow - $curr_weekday);
  }
  else {
    $days -= $curr_weekday - $dow;
  }
  return date_calc_days_to_date($days, $format);
}