Title: get_weekstartend
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_weekstartend( string $mysqlstring, int|string $start_of_week ): int[]

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_weekstartend/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_weekstartend/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_weekstartend/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_weekstartend/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_weekstartend/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_weekstartend/?output_format=md#wp--skip-link--target)

Gets the week start and end from the datetime or date string from MySQL.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_weekstartend/?output_format=md#parameters)󠁿

 `$mysqlstring`stringrequired

Date or datetime field type from MySQL.

`$start_of_week`int|stringoptional

Start of the week as an integer. Default empty string.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_weekstartend/?output_format=md#return)󠁿

 int[] Week start and end dates as Unix timestamps.

 * `start` int
 * The week start date as a Unix timestamp.
 * `end` int
 * The week end date as a Unix timestamp.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_weekstartend/?output_format=md#source)󠁿

    ```php
    function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
    	// MySQL string year.
    	$my = substr( $mysqlstring, 0, 4 );

    	// MySQL string month.
    	$mm = substr( $mysqlstring, 8, 2 );

    	// MySQL string day.
    	$md = substr( $mysqlstring, 5, 2 );

    	// The timestamp for MySQL string day.
    	$day = mktime( 0, 0, 0, $md, $mm, $my );

    	// The day of the week from the timestamp.
    	$weekday = (int) gmdate( 'w', $day );

    	if ( ! is_numeric( $start_of_week ) ) {
    		$start_of_week = (int) get_option( 'start_of_week' );
    	}

    	if ( $weekday < $start_of_week ) {
    		$weekday += 7;
    	}

    	// The most recent week start day on or before $day.
    	$start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week );

    	// $start + 1 week - 1 second.
    	$end = $start + WEEK_IN_SECONDS - 1;

    	return compact( 'start', 'end' );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/functions.php#L587)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/functions.php#L587-L618)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_weekstartend/?output_format=md#related)󠁿

| Uses | Description | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

| Used by | Description | 
| [wp_get_archives()](https://developer.wordpress.org/reference/functions/wp_get_archives/)`wp-includes/general-template.php` |

Displays archive links based on type and format.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_weekstartend/?output_format=md#changelog)󠁿

| Version | Description | 
| [0.71](https://developer.wordpress.org/reference/since/0.71/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_weekstartend%2F)
before being able to contribute a note or feedback.