PHP and MySQL syntax: Difference between revisions

Jump to navigation Jump to search
Line 7: Line 7:
* 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 '{{Template:Today}} 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 '{{Template:Today}} 10:05:06'
* mysql:  
* mysql:  
** {{kbd | key=<nowiki>SELECT NOW();</nowiki>}} /*return the human readable current time: {{Template:Today}} 12:19:43 */ which mapping to {{kbd | key=<nowiki>DATETIME</nowiki>}} type<ref>[http://dev.mysql.com/doc/refman/5.1/en/datetime.html MySQL :: MySQL 5.1 Reference Manual :: 11.3.1 The DATE, DATETIME, and TIMESTAMP Types]</ref>
** {{kbd | key=<nowiki>SELECT NOW();</nowiki>}} Returns {{Template:Today}} 12:19:43 */ which mapping to {{kbd | key=<nowiki>DATETIME</nowiki>}} type<ref>[http://dev.mysql.com/doc/refman/5.1/en/datetime.html MySQL :: MySQL 5.1 Reference Manual :: 11.3.1 The DATE, DATETIME, and TIMESTAMP Types]</ref>
** {{kbd | key=<nowiki>SELECT NOW()+0;</nowiki>}} //2011-04-01 12:19:43 returns 20110401122023.000000
** {{kbd | key=<nowiki>SELECT NOW()+0;</nowiki>}} //2011-04-01 12:19:43 returns 20110401122023.000000
** {{kbd | key=<nowiki>SELECT CURRENT_TIMESTAMP;</nowiki>}} /*return the human readable current time: {{Template:Today}} 12:19:43 */ {{exclaim}} [http://stackoverflow.com/questions/2934258/how-do-i-get-the-current-time-zone-of-mysql Current time zone of MySQL] is SYSTEM.
** {{kbd | key=<nowiki>SELECT CURRENT_TIMESTAMP;</nowiki>}} /*return the human readable current time: {{Template:Today}} 12:19:43 */ {{exclaim}} [http://stackoverflow.com/questions/2934258/how-do-i-get-the-current-time-zone-of-mysql Current time zone of MySQL] is SYSTEM.
** {{kbd | key=<nowiki>SELECT  CURRENT_DATE;</nowiki>}} or {{kbd | key=<nowiki>SELECT  CURDATE();</nowiki>}}  /* Return {{CURRENTYEAR}}-{{CURRENTMONTH}}-{{CURRENTDAY2}} */<ref>[http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_curdate MySQL :: MySQL 5.5 Reference Manual :: 12.7 Date and Time Functions]</ref>
 
* EXCEL: {{kbd | key=<nowiki>=TODAY()</nowiki>}} Returns the current date. ex: {{CURRENTYEAR}}/{{CURRENTMONTH}}/{{CURRENTDAY2}} <ref>[http://office.microsoft.com/en-gb/excel-help/today-function-HP010062297.aspx TODAY function - Excel - Office.com]</ref>
get current date
* MySQL: {{kbd | key=<nowiki>SELECT  CURRENT_DATE;</nowiki>}} or {{kbd | key=<nowiki>SELECT  CURDATE();</nowiki>}}  Returns {{Template:Today}} <ref>[http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_curdate MySQL :: MySQL 5.5 Reference Manual :: 12.7 Date and Time Functions]</ref>
* EXCEL: {{kbd | key=<nowiki>=TODAY()</nowiki>}} Returns {{CURRENTYEAR}}/{{CURRENTMONTH}}/{{CURRENTDAY2}} <ref>[http://office.microsoft.com/en-gb/excel-help/today-function-HP010062297.aspx TODAY function - Excel - Office.com]</ref>
* shell script in {{Linux}} or {{Mac}}:  {{kbd | key=<nowiki> echo `date +\%Y-\%m-\%d` 2>&1</nowiki>}} Returns {{Template:Today}}


the current '''timestamp''' ex: 1292897201
the current '''timestamp''' ex: 1292897201

Navigation menu