Last active
June 30, 2016 14:57
-
-
Save luckyshot/6073369 to your computer and use it in GitHub Desktop.
PHP Dates and times examples
This file contains 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 | |
// Full documentation: | |
// http://php.net/manual/en/function.date.php | |
// Set timezone to avoid PHP warning | |
date_default_timezone_set( 'Europe/London' ); | |
date_default_timezone_set( 'Europe/Madrid' ); | |
// 2014-12-31 23:59:59 (MySQL datetime) | |
date( 'Y-m-d H:i:s' ); | |
date( 'Y-m-d H:i:s', time() ); | |
// reverse | |
strtotime( $date ); | |
// Thursday, 10 March 2016 (15:28:46) | |
date( 'l, j F Y (H:i:s)' ); | |
// Wednesday, 29th of June 2016 at 12:30h | |
date( 'l, jS \of F Y \a\t h:i\h' ); | |
// Monday 31th of July 2014 23:59:59 PM | |
date( 'l jS \of F Y h:i:s A' ); | |
// Nov 12th, 17:32 | |
date('M jS, H:i'); | |
// July 31th | |
date( 'F jS' ); | |
// 31/12/2014 | |
date( 'd/m/Y' ); | |
// 31/12/14 23:59:59 | |
date( 'd/m/y H:i:s' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment