SQL/MySQL/Date Time/Date Format — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 10:16, 26 мая 2010

Format a date 1

/*mysql> SELECT DATE_FORMAT("2078-08-30 21:19:58", "%W %M %d %Y");
+---------------------------------------------------+
| DATE_FORMAT("2078-08-30 21:19:58", "%W %M %d %Y") |
+---------------------------------------------------+
| Tuesday August 30 2078                            |
+---------------------------------------------------+
1 row in set (0.02 sec)
*/
SELECT DATE_FORMAT("2078-08-30 21:19:58", "%W %M %d %Y");



Format a date 2

/*
mysql> SELECT DATE_FORMAT("2078-08-30 21:19:58", "%a. %b %e, "%y");
+------------------------------------------------------+
| DATE_FORMAT("2078-08-30 21:19:58", "%a. %b %e, "%y") |
+------------------------------------------------------+
| Tue. Aug 30, "78                                     |
+------------------------------------------------------+
1 row in set (0.00 sec)

*/  
SELECT DATE_FORMAT("2078-08-30 21:19:58", "%a. %b %e, "%y");



Format a date 3

/*
mysql> SELECT DATE_FORMAT("2078-08-30 21:19:58", "%m-%e-%Y %l:%i%p");
+--------------------------------------------------------+
| DATE_FORMAT("2078-08-30 21:19:58", "%m-%e-%Y %l:%i%p") |
+--------------------------------------------------------+
| 08-30-2078 9:19PM                                      |
+--------------------------------------------------------+
1 row in set (0.00 sec)

*/  
SELECT DATE_FORMAT("2078-08-30 21:19:58", "%m-%e-%Y %l:%i%p");



Format a date 4

/*
mysql> SELECT DATE_FORMAT("2078-08-30 21:19:58", "%m-%e-%Y %h:%i%s%p %W");
+-------------------------------------------------------------+
| DATE_FORMAT("2078-08-30 21:19:58", "%m-%e-%Y %h:%i%s%p %W") |
+-------------------------------------------------------------+
| 08-30-2078 09:1958PM Tuesday                                |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

*/  
SELECT DATE_FORMAT("2078-08-30 21:19:58", "%m-%e-%Y %h:%i%s%p %W");



Format a date 5

/*
mysql> SELECT DATE_FORMAT("2078-08-30 21:19:58", "%M %D,%Y %k:%i CST %W");
+-------------------------------------------------------------+
| DATE_FORMAT("2078-08-30 21:19:58", "%M %D,%Y %k:%i CST %W") |
+-------------------------------------------------------------+
| August 30th,2078 21:19 CST Tuesday                          |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

*/  
SELECT DATE_FORMAT("2078-08-30 21:19:58", "%M %D,%Y %k:%i CST %W");