get_weekstartend()从MySQL日期时间或日期字符串中获取一周的开始或结束时间

目录

描述

译文

从MySQL日期时间或日期字符串中获取一周的开始或结束时间。

原文

Get the week start and end from the MySQL DATETIME or date string.

get_weekstartend() 描述

用法

<?php get_weekstartend$mysqlstring$start_of_week ?>

get_weekstartend() 用法

参数

$mysqlstring

(string) (必填) Date or MySQL DATETIME field type.

默认值: None

$start_of_week

(integer) (可选) Start of the week as an integer.

默认值: ''

get_weekstartend() 参数

返回值

(array) 

Keys are 'start' and 'end'.

get_weekstartend() 返回值

注意

  • 使用到: get_option() to retrieve the 'start_of_week' option if $start_of_week is not numeric.

get_weekstartend() 注意

历史

添加于 版本: 0.71

get_weekstartend() 历史

源文件

get_weekstartend() 函数的代码位于 wp-includes/functions.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Get the week start and end from the datetime or date string from MySQL.
 *
 * @since 0.71
 *
 * @param string     $mysqlstring   Date or datetime field type from MySQL.
 * @param int|string $start_of_week Optional. Start of the week as an integer. Default empty string.
 * @return array Keys are 'start' and 'end'.
 */
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 = date( 'w', $day );

	if ( !is_numeric($start_of_week) )
		$start_of_week = 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="" +="" 7="" days="" -="" 1="" second.="" $end="$start" +="" 7="" *="" day_in_seconds="" -="" 1;="" return="" compact(="" 'start',="" 'end'="" );="" }="">

get_weekstartend() 源文件