Definition:
function get_weekstartend( $mysqlstring, $start_of_week = '' ) {}
Get the week start and end from the datetime or date string from mysql.
Parameters
- string $mysqlstring: Date or datetime field type from mysql.
- int $start_of_week: Optional. Start of the week as an integer.
Return values
returns:Keys are ‘start’ and ‘end’.
Source code
function get_weekstartend( $mysqlstring, $start_of_week = '' ) { $my = substr( $mysqlstring, 0, 4 ); // Mysql string Year $mm = substr( $mysqlstring, 8, 2 ); // Mysql string Month $md = substr( $mysqlstring, 5, 2 ); // Mysql string day $day = mktime( 0, 0, 0, $md, $mm, $my ); // The timestamp for mysqlstring day. $weekday = date( 'w', $day ); // The day of the week from the timestamp if ( !is_numeric($start_of_week) ) $start_of_week = get_option( 'start_of_week' ); if ( $weekday < $start_of_week ) $weekday += 7; $start = $day - 86400 * ( $weekday - $start_of_week ); // The most recent week start day on or before $day $end = $start + 604799; // $start + 7 days - 1 second return compact( 'start', 'end' ); }
1909
No comments yet... Be the first to leave a reply!