返回介绍

get_weekstartend()

发布于 2017-09-11 00:46:20 字数 2017 浏览 1042 评论 0 收藏 0

get_weekstartend( string $mysqlstring,  int|string $start_of_week = '' )

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


description


参数

$mysqlstring

(string) (Required) Date or datetime field type from MySQL.

$start_of_week

(int|string) (Optional) Start of the week as an integer.

Default value: ''


返回值

(array) Keys are 'start' and 'end'.


源代码

File: wp-includes/functions.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 = 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 + 1 week - 1 second.
	$end = $start + WEEK_IN_SECONDS - 1;
	return compact( 'start', 'end' );
}

更新日志

Versiondescription
0.71Introduced.

相关函数

Uses

  • wp-includes/option.php: get_option()

Used By

  • wp-includes/general-template.php: wp_get_archives()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文