MySQL time functions from_unixtime () date_format () unix_timestamp () now () instructions

MySQL time functions from_unixtime () date_format () unix_timestamp () now () instructions

now () the current time
MySQL> the SELECT now ();
+ --------------------- +
| now () |
+ --------- + ------------
| 2018-09-10 19:20:19 |
+ --------------------- +
1
2
. 3
. 4
. 5
. 6
UNIX_TIMESTAMP () current timestamp
MySQL> SELECT UNIX_TIMESTAMP ();
+ ------------------ +
| UNIX_TIMESTAMP () |
+ ------- + -----------
| 1536578429 |
+ ------------------ +
. 1
2
. 3
. 4
. 5
. 6
UNIX_TIMESTAMP (now ()) converting the current time into a timestamp
MySQL> the SELECT unix_timestamp (now ());
+ ----------------------- +
| unix_timestamp (now ()) |
+ --- -------------------- +
| 1536578445 |
+ ----------------------- +
. 1
2
. 3
. 4
. 5
. 6
UNIX_TIMESTAMP ( '2018-08-08') is converted into the specified time stamp
MySQL> SELECT UNIX_TIMESTAMP ( '2018-08-08');
+ ------------------------------ +
| UNIX_TIMESTAMP ( ' 2018-08-08 ') |
+ ------------------------------ +
| 1533657600 |
+ ------ + ------------------------
. 1
2
. 3
. 4
. 5
. 6
FROM_UNIXTIME (1,533,657,600) is converted to the time stamp format default '% Y-% m- D% H%:% I:% S '
MySQL> SELECT FROM_UNIXTIME (1533657600);
+ + ---------------------------
| FROM_UNIXTIME (1533657600) |
+ --------------------------- +
| 2018-08-08 00:00:00 |
--------------------------- + +
. 1
2
. 3
. 4
. 5
. 6
FROM_UNIXTIME (1,533,657,600, 'M-%%% Y-D') converting the timestamp time and format
MySQL> SELECT FROM_UNIXTIME (1533657600, 'M-%%% Y-D');
+ -------------------- + -------------------
| FROM_UNIXTIME (1533657600, 'M-%%% Y-D') |
+ ----------------------- + ---------------------------
| 2018-08-08 |
+ -------------- ------------------------- +
. 1
2
. 3
. 4
. 5
. 6
query timestamp field into a display time format
mysql> select from_unixtime (ctime, ' % M-% D% Y-') from logs limit. 1;
+ ---------------------------------- +
| FROM_UNIXTIME (the ctime, 'M-%%% Y-D') |
+ -------------------------------- - +
| 2018-09-18 |
+ ---------------------------------- +
. 1
2
. 3
. 4
. 5
. 6
WHERE timestamp field
MySQL> SELECT COUNT (*) WHERE FROM_UNIXTIME from logs (the ctime, '% m% D% the Y') = 20,180,808 limit. 1;
+ ---------- +
| COUNT (*) |
+ + ----------
| 12345 |
+ ---------- +
. 1
2
. 3
. 4
. 5
. 6
DATE_FORMAT () display time format
mysql> select date_format (now () , 'the Y% /% m /% D');
+ -------------------------------- +
| DATE_FORMAT (now (), 'the Y% /% m /% D') |
+ -------------------------------- +
| 2018/08/08 |
+ -------------------------------- +
. 1
2
. 3
. 4
. 5
. 6
WHERE time field
MySQL> SELECT COUNT (*) WHERE DATE_FORMAT from logs (CDate, '% m% D% the Y') = 20.18091 million limit. 1;
+ ---------- +
| COUNT (*) |
+ ---------- +
| 123 |
+ ----------
+ ----------------
Disclaimer: This article is CSDN bloggers 'gocuber' original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/gocuber/article/details/80195591

Guess you like

Origin www.cnblogs.com/apolloren/p/12106496.html