PHP and MySQL syntax: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
Convert time stamp <--> the human readable time format | |||
== now == | |||
the human readable time format ex: 2010-12-21 10:05:06 | the human readable time format ex: 2010-12-21 10:05:06 | ||
* php: | * php: echo date("y-m-d H:i:s", time() ); //Convert the time stamp of current time to the human readable time format. Ex: return '2010-12-21 10:05:06' | ||
* mysql: SELECT NOW(); /*the human readable current time */ | * mysql: SELECT NOW(); /*the human readable current time */ | ||
| Line 8: | Line 8: | ||
* php: echo time(); | * php: echo time(); | ||
* mysql: SELECT NOW()+0; | * mysql: SELECT NOW()+0; | ||
== specified time == | |||
the human readable time format ex: 2010-12-21 10:05:06 | |||
* php: echo date("y-m-d H:i:s", 1292897201 ); // convert the time stamp 1292897201 to the human readable time format | |||
convert human-readable time to timestamp | convert human-readable time to timestamp | ||
| Line 13: | Line 17: | ||
* mysql: select UNIX_TIMESTAMP('2011-03-15 18:53:57'); /* return timestamp: 1300186437 */ | * mysql: select UNIX_TIMESTAMP('2011-03-15 18:53:57'); /* return timestamp: 1300186437 */ | ||
time difference of two time values | == time difference of two time values == | ||
* php: using mktime() function | * php: using mktime() function | ||
* mysql: SELECT TIMEDIFF('2010:01:01 00:00:00', '2010:02:01 00:00:00'); /* return -744:00:00 */ | * mysql: SELECT TIMEDIFF('2010:01:01 00:00:00', '2010:02:01 00:00:00'); /* return -744:00:00 */ | ||
Revision as of 18:24, 22 March 2011
Convert time stamp <--> the human readable time format
now
the human readable time format ex: 2010-12-21 10:05:06
- php: echo date("y-m-d H:i:s", time() ); //Convert the time stamp of current time to the human readable time format. Ex: return '2010-12-21 10:05:06'
- mysql: SELECT NOW(); /*the human readable current time */
the current timestamp ex: 1292897201
- php: echo time();
- mysql: SELECT NOW()+0;
specified time
the human readable time format ex: 2010-12-21 10:05:06
- php: echo date("y-m-d H:i:s", 1292897201 ); // convert the time stamp 1292897201 to the human readable time format
convert human-readable time to timestamp
- php:
- mysql: select UNIX_TIMESTAMP('2011-03-15 18:53:57'); /* return timestamp: 1300186437 */
time difference of two time values
- php: using mktime() function
- mysql: SELECT TIMEDIFF('2010:01:01 00:00:00', '2010:02:01 00:00:00'); /* return -744:00:00 */