CURDATE() : Current Date in MySQL

Syntax of CURDATE()
CURDATE()
Example :
SELECT CURDATE(); 
Output is 2019-04-25 , this is in the format YYYY-MM-DD

NOW() & CURDATE()

By using CURDATE() we get the date part only, where as by using NOW() we will get both date and time.

Yesterday & Tomorrow date by usign CURDATE()

SELECT CURDATE()- interval 1 day  as Yesterday, CURDATE() as Today, CURDATE()+ interval 1 day as Tomorrow
YesterdayTodayTomorrow
2019-04-242019-04-252019-04-26

Last Month , Today and Next Month

SELECT CURDATE()- interval 1 month  as LastMonth, CURDATE() as Today, CURDATE()+ interval 1 Month as NextMonth
Last MonthTodayNext Month
2019-03-252019-04-252019-05-25

First Day of Previous Month

SELECT DATE_FORMAT(CURDATE() - INTERVAL 1 MONTH,'%Y-%m-01')

Last Day of Previous Month

SELECT LAST_DAY(CURDATE() - INTERVAL 1 MONTH)
Last Month First DayLast Month Last Day
2019-03-012019-03-31

Present Month Records

Starting from 1st day of the current month till now.
SELECT * FROM `dt_table` WHERE  date between  DATE_FORMAT(CURDATE() ,'%Y-%m-01') AND CURDATE()

Adding current date and time by default to a record.

While storing a record MySQL can automatically insert date and time in a column.

Read more on how to store default date and time in MySQL table here.

Examples of CURDATE() to get different range of records.

Visitors Rating
Your Rating




Post Comment This is for short comments only. Use the forum for more discussions.








HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer