There are various pre defined function for data and time we will see them one by one.
If you want to show current time then we use CURTIME().It returns time in HH:MM:SS string format
1 2 3 4 5 6 7 8 9 | mysql>SELECT CURTIME(); +-----------+ | CURTIME() | +-----------+ | 16:06:23 | +-----------+ 1 row in set (0.06 sec) |
below is HHMMSS in numeric format
1 2 3 4 5 6 7 | mysql> select CURTIME()+0; +-------------+ | CURTIME()+0 | +-------------+ | 162404 | +-------------+ 1 row in set (0.06 sec) |
To select current data we use CURDATE().It returns data in YYYY-MM-DD string format.
1 2 3 4 5 6 7 | mysql> SELECT CURDATE(); +------------+ | CURDATE() | +------------+ | 2017-04-05 | +------------+ 1 row in set (0.00 sec) |
to convert string in to number we use following query
1 2 3 4 5 6 7 | mysql> SELECT CURDATE()+0; +-------------+ | CURDATE()+0 | +-------------+ | 20170405 | +-------------+ 1 row in set (0.06 sec) |
To select current data and time we use NOW() whch returns data and time in ‘YYYY:MM:DD HH:MM:SS’ in string format or YYYYMMDDHHMMSS is numeric format.
1 2 3 4 5 6 7 | mysql> select NOW(); +---------------------+ | NOW() | +---------------------+ | 2017-04-05 16:32:54 | +---------------------+ 1 row in set (0.00 sec) |
1 2 3 4 5 6 7 | mysql> select NOW()+0; +----------------+ | NOW()+0 | +----------------+ | 20170405163336 | +----------------+ 1 row in set (0.00 sec) |