Last active
June 1, 2017 17:16
-
-
Save thenbrent/9698083 to your computer and use it in GitHub Desktop.
Testing strtotime() input/output for a variety of strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
******* strtotime() test run on Friday (2014-03-21 22:28:50-UTC) ********** | |
---- testing day of week ---- | |
Wednesday = 2014-03-26 <-- the next Wednesday (not the last) | |
Wednesday next week = 2014-04-02 <-- interpretted as "the first Wednesday after one week from today" rather than "the next Wednesday" | |
Friday = 2014-03-21 <-- today! | |
Friday next week = 2014-03-28 <-- one week | |
---- testing day of month ---- | |
First day of March = 1970-01-01 <-- requires specific integer day (i.e. date( 't' ) ) | |
first day March = 2014-03-22 <-- does not compute | |
First day of the month = 1970-01-01 <-- requires specific integer day (i.e. date( 't' ) ) | |
first day next month = 2014-04-22 <-- does not compute | |
10 = 1970-01-01 <-- requires month | |
21 = 1970-01-01 <-- requires month | |
10th = 1970-01-01 <-- requires month | |
21st = 1970-01-01 <-- requires month | |
10th day = 1970-01-01 <-- requires month | |
21st day = 1970-01-01 <-- requires month | |
Last day of March = 1970-01-01 <-- requires specific integer day (i.e. date( 't' ) ) | |
last day March = 2014-03-20 <-- yesterday? | |
Last day of the month = 1970-01-01 <-- requires specific integer day (i.e. date( 't' ) ) | |
last day next month = 2014-04-20 <-- interpretted as "one month from yesterday" | |
---- testing day of year ---- | |
10 February = 2014-03-10 <-- the 10th of February this year (in the past) | |
10 February next year = 2015-03-10 <-- the 10th of February next year | |
10 March = 2014-03-10 <-- the 10th of March this year (in the past) | |
10 March next year = 2015-03-10 <-- the 10th of March next year | |
21 March = 2014-03-21 <-- today! | |
21 March next year = 2015-03-21 <-- one year | |
30 March = 2014-03-30 <-- the next 30th of March | |
30 March next year = 2015-03-30 <-- interpretted as "the first 30th March after one year from today" rather than "the next 30th March" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$from_timestamp = gmdate( "U" ); | |
$current_day = gmdate( "j" ); | |
$current_month = gmdate( "F" ); | |
error_log( "******* strtotime() test run on " . gmdate( "l" ) . " (" . gmdate( "Y-m-d H:i:s-e" ) . ") **********" ); | |
error_log( "- 1 months = " . date( "Y-m-d", strtotime( "- 1 months", $from_timestamp ) ) ); | |
error_log( "- 3 months = " . date( "Y-m-d", strtotime( "- 3 months", $from_timestamp ) ) ); | |
error_log( "+ 1 months = " . date( "Y-m-d", strtotime( "+ 1 months", $from_timestamp ) ) ); | |
error_log( "+ 3 months = " . date( "Y-m-d", strtotime( "+ 3 months", $from_timestamp ) ) ); | |
error_log( "---- testing day of week ----" ); | |
error_log( "Wednesday = " . date( "Y-m-d", strtotime( "Wednesday", $from_timestamp ) ) ); | |
error_log( "Wednesday next week = " . date( "Y-m-d", strtotime( "Wednesday next week", $from_timestamp ) ) ); | |
error_log( "Friday = " . date( "Y-m-d", strtotime( "Friday", $from_timestamp ) ) ); | |
error_log( "Friday next week = " . date( "Y-m-d", strtotime( "Friday next week", $from_timestamp ) ) ); | |
error_log( "---- testing day of month ----" ); | |
error_log( "First day of {$current_month} = " . date( "Y-m-d", strtotime( "First day of {$current_month}", $from_timestamp ) ) ); | |
error_log( "first day {$current_month} = " . date( "Y-m-d", strtotime( "first day {$current_month}", $from_timestamp ) ) ); | |
error_log( "First day of the month = " . date( "Y-m-d", strtotime( "First day of the month", $from_timestamp ) ) ); | |
error_log( "first day next month = " . date( "Y-m-d", strtotime( "first day next month", $from_timestamp ) ) ); | |
error_log( "10 = " . date( "Y-m-d", strtotime( "10", $from_timestamp ) ) ); | |
error_log( "{$current_day} = " . date( "Y-m-d", strtotime( "{$current_day}", $from_timestamp ) ) ); | |
error_log( "10th = " . date( "Y-m-d", strtotime( "10th", $from_timestamp ) ) ); | |
error_log( "{$current_day}th = " . date( "Y-m-d", strtotime( "{$current_day}th", $from_timestamp ) ) ); | |
error_log( "10th day = " . date( "Y-m-d", strtotime( "10th day", $from_timestamp ) ) ); | |
error_log( "{$current_day}th day = " . date( "Y-m-d", strtotime( "{$current_day}st day", $from_timestamp ) ) ); | |
error_log( "Last day of {$current_month} = " . date( "Y-m-d", strtotime( "Last day of {$current_month}", $from_timestamp ) ) ); | |
error_log( "last day {$current_month} = " . date( "Y-m-d", strtotime( "last day {$current_month}", $from_timestamp ) ) ); | |
error_log( "Last day of the month = " . date( "Y-m-d", strtotime( "Last day of the month", $from_timestamp ) ) ); | |
error_log( "last day next month = " . date( "Y-m-d", strtotime( "last day next month", $from_timestamp ) ) ); | |
error_log( "---- testing day of year ----" ); | |
error_log( "10 February = " . date( "Y-m-d", strtotime( "10 February", $from_timestamp ) ) ); | |
error_log( "10 February next year = " . date( "Y-m-d", strtotime( "10 February next year", $from_timestamp ) ) ); | |
error_log( "10 {$current_month} = " . date( "Y-m-d", strtotime( "10 {$current_month}", $from_timestamp ) ) ); | |
error_log( "10 {$current_month} next year = " . date( "Y-m-d", strtotime( "10 {$current_month} next year", $from_timestamp ) ) ); | |
error_log( "{$current_day} {$current_month} = " . date( "Y-m-d", strtotime( "{$current_day} {$current_month}", $from_timestamp ) ) ); | |
error_log( "{$current_day} {$current_month} next year = " . date( "Y-m-d", strtotime( "{$current_day} {$current_month} next year", $from_timestamp ) ) ); | |
error_log( "30 {$current_month} = " . date( "Y-m-d", strtotime( "30 {$current_month}", $from_timestamp ) ) ); | |
error_log( "30 {$current_month} next year = " . date( "Y-m-d", strtotime( "30 {$current_month} next year", $from_timestamp ) ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment