MySQL CURDATE() Function
The CURDATE() function returns the current date.
The date is returned as "YYYY-MM-DD" (string) or as YYYYMMDD (numeric).
Note: This function equals the CURRENT_DATE() function.
SELECT CURDATE() + 1;
----------
MySQL CURRENT_DATE() Function
--------
MySQL CURRENT_TIME() Function
MySQL CURTIME() Function
-----------
MySQL CURRENT_TIMESTAMP() Function
------------
The DATE() function extracts the date part from a datetime expression.
SELECT DATE("2021-06-03 09:34:21");
----------
The DATEDIFF() function returns the number of days between two date values.
DATEDIFF(date1, date2)
SELECT DATEDIFF("2021-06-25 09:34:21", "2017-05-02 15:25:35");
------------
The DATE_ADD() function adds a time/date interval to a date and then returns the date.
DATE_ADD(date, INTERVAL value addunit)
MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
SECOND_MICROSECOND
MINUTE_MICROSECOND
MINUTE_SECOND
HOUR_MICROSECOND
HOUR_SECOND
HOUR_MINUTE
DAY_MICROSECOND
DAY_SECOND
DAY_MINUTE
DAY_HOUR
YEAR_MONTH
SELECT DATE_ADD("2017-06-15", INTERVAL -2 MONTH);
=======================
Mounika@MOUNIKA-PC c:\xampp
# ram.cmd
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.4.18-MariaDB mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use vlrinst;
Database changed
MariaDB [vlrinst]> curdate();
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'curdate()' at line 1
MariaDB [vlrinst]> select curdate();
+------------+
| curdate() |
+------------+
| 2021-06-03 |
+------------+
1 row in set (0.001 sec)
MariaDB [vlrinst]> select curdate()+0;
+-------------+
| curdate()+0 |
+-------------+
| 20210603 |
+-------------+
1 row in set (0.000 sec)
MariaDB [vlrinst]> select curdate()+3;
+-------------+
| curdate()+3 |
+-------------+
| 20210606 |
+-------------+
1 row in set (0.001 sec)
MariaDB [vlrinst]> select currentdate()+3;
ERROR 1305 (42000): FUNCTION vlrinst.currentdate does not exist
MariaDB [vlrinst]> select current-date()+3;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')+3' at line 1
MariaDB [vlrinst]> select current_date()+3;
+------------------+
| current_date()+3 |
+------------------+
| 20210606 |
+------------------+
1 row in set (0.000 sec)
MariaDB [vlrinst]> select current_date();
+----------------+
| current_date() |
+----------------+
| 2021-06-03 |
+----------------+
1 row in set (0.000 sec)
MariaDB [vlrinst]> select current_time();
+----------------+
| current_time() |
+----------------+
| 23:26:00 |
+----------------+
1 row in set (0.000 sec)
MariaDB [vlrinst]> select current_time();
+----------------+
| current_time() |
+----------------+
| 23:26:06 |
+----------------+
1 row in set (0.000 sec)
MariaDB [vlrinst]> select current_time()+20;
+-------------------+
| current_time()+20 |
+-------------------+
| 232633 |
+-------------------+
1 row in set (0.000 sec)
MariaDB [vlrinst]> select current_time()+20,current_time();
+-------------------+----------------+
| current_time()+20 | current_time() |
+-------------------+----------------+
| 232654 | 23:26:34 |
+-------------------+----------------+
1 row in set (0.000 sec)
MariaDB [vlrinst]> select curtime()+20,current_time();
+--------------+----------------+
| curtime()+20 | current_time() |
+--------------+----------------+
| 232668 | 23:26:48 |
+--------------+----------------+
1 row in set (0.000 sec)
MariaDB [vlrinst]> select current_timestamp();
+---------------------+
| current_timestamp() |
+---------------------+
| 2021-06-03 23:27:15 |
+---------------------+
1 row in set (0.000 sec)
MariaDB [vlrinst]> select current_timestamp()+15;
+------------------------+
| current_timestamp()+15 |
+------------------------+
| 20210603232740 |
+------------------------+
1 row in set (0.000 sec)
MariaDB [vlrinst]> select date(current_timestamp());
+---------------------------+
| date(current_timestamp()) |
+---------------------------+
| 2021-06-03 |
+---------------------------+
1 row in set (0.019 sec)
MariaDB [vlrinst]> select * from vlr;
+-------------------------------------+---------------------+---------------------+
| comment | created_at | changed_at |
+-------------------------------------+---------------------+---------------------+
| Please save my number +919059868766 | 2021-05-26 22:32:47 | 2021-05-26 22:36:50 |
| please subcribe vlr | 2021-05-26 22:36:01 | 2021-05-26 22:36:01 |
+-------------------------------------+---------------------+---------------------+
2 rows in set (0.001 sec)
MariaDB [vlrinst]> select date(created_at),Created_at from vlr;
+------------------+---------------------+
| date(created_at) | Created_at |
+------------------+---------------------+
| 2021-05-26 | 2021-05-26 22:32:47 |
| 2021-05-26 | 2021-05-26 22:36:01 |
+------------------+---------------------+
2 rows in set (0.001 sec)
MariaDB [vlrinst]> SELECT DATE("2021-06-03 09:34:21");
+-----------------------------+
| DATE("2021-06-03 09:34:21") |
+-----------------------------+
| 2021-06-03 |
+-----------------------------+
1 row in set (0.000 sec)
MariaDB [vlrinst]> select Datediff("2017-05-02",curDate());
+----------------------------------+
| Datediff("2017-05-02",curDate()) |
+----------------------------------+
| -1493 |
+----------------------------------+
1 row in set (0.001 sec)
MariaDB [vlrinst]> select Datediff("2017-05-02",curDate());
+----------------------------------+
| Datediff("2017-05-02",curDate()) |
+----------------------------------+
| -1493 |
+----------------------------------+
1 row in set (0.000 sec)
MariaDB [vlrinst]> select Datediff("2017-05-02","1947-08-15");
+-------------------------------------+
| Datediff("2017-05-02","1947-08-15") |
+-------------------------------------+
| 25463 |
+-------------------------------------+
1 row in set (0.001 sec)
MariaDB [vlrinst]>