calendar_week_mod()WP 1.5.0

Translates the entered integer to the number of days since the beginning of the week: 8=1 (8-7), 15=1 (15-7*2).

The function returns the remainder of the division by 7 — how many days have passed since the beginning of the week.

return (int) $num % 7;

Examples:

  • calendar_week_mod(8)1 (the 8th day is the 1st day of the next week)
  • calendar_week_mod(15)1 (15 % 7 = 1)

Useful for calculating weekdays based on dates or cycles.

No Hooks.

Returns

float. The number of days since the beginning of the week.

Usage

calendar_week_mod( $num );
$num(integer) (required)
The integer that needs to be transformed.

Examples

0

#1 Demonstration examples

echo calendar_week_mod( 15 ); // 1 (7*2+1)
echo calendar_week_mod( 8 );  // 1 (7+1)
echo calendar_week_mod( 30 ); // 2 (7*4+2)
echo calendar_week_mod( 50 ); // 2 (7*8+2)

Changelog

Since 1.5.0 Introduced.

calendar_week_mod() code WP 6.8.1

function calendar_week_mod( $num ) {
	$base = 7;
	return ( $num - $base * floor( $num / $base ) );
}