Get Weekday Index. eg) 4/14/2016 = 2nd Thursday

<?php /** * Get weekday index from a Unix Timestamp * Useful for extracting a BYSETPOS for an RRULE * * @param int $timestamp a unix timestamp * * @author Michael Niles <codepad@blindmikey.com> * @version 1.0.0 */ function get_weekday_index ( $timestamp ) { $day = date( 'Ymd', $timestamp ); $timestamp = strtotime( $day ); $weekday = date( 'l', $timestamp ); $month = date( 'F', $timestamp ); $year = date( 'Y', $timestamp ); $compare = array( '-1' => 'last', '1' => 'first', '2' => 'second', '3' => 'third', '4' => 'fourth', '5' => 'fifth', ); foreach ( $compare as $key => $context ) { if ( $timestamp == strtotime( $context .' '. $weekday .' of '. $month .' '. $year ) ) { return $key; } } return 0; }
Get weekday index from a Unix Timestamp
Useful for extracting a BYSETPOS for an RRULE

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.