NOW() : Current Date & Time in MySQL

Syntax of NOW()
NOW()
Example :
SELECT NOW(); 
Output is 2016-09-17 16:49:41 , this is in the format YYY-MM-DD HH:MM:SS

Now as a number
20160917165099.000000

Yesterday & Tomorrow date by usign NOW()

SELECT NOW()- interval 1 day  as Yesterday, NOW() as Today, NOW()+ interval 1 day as Tomorrow
YesterdayTodayTomorrow
2019-08-17 17:04:572019-08-18 17:04:572019-08-19 17:04:57

Last Month , Today and Next Month

SELECT NOW()- interval 1 month  as LastMonth, NOW() as Today, NOW()+ interval 1 Month as NextMonth
Last MonthTodayNext Month
2019-07-18 17:04:572019-08-18 17:04:572019-09-18 17:04:57

Matching only date part ( not time ) with datetime field or Now()

We may store date with time in a table in the above mentioned date and time format. However we can compare the date part only ( without time ) to match the records. Example : We may be storing date and time of login of members in a table but want display all the login members of today or a particular date.
SELECT * from table_name WHERE DATE(date_column)='2019-12-26'
To match current or today's date
SELECT * from table_name WHERE DATE(date_column)=CURDATE()

Read more on 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.

Visitors Rating
Your Rating




Post your comments , suggestion , error , requirements etc here .








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