Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql query to get current date from database? [closed]

Tags:

Can anyone please suggest the query to get current date from data base ?

like image 702
user2740576 Avatar asked Jan 07 '14 12:01

user2740576


People also ask

How do I get the current date in MySQL query?

MySQL CURDATE() Function The CURDATE() function returns the current date. Note: The date is returned as "YYYY-MM-DD" (string) or as YYYYMMDD (numeric).

How can I get current date data?

Simply use the CURDATE() function to get the current date. The date can be displayed in two different formats: ' YYYY-MM-DD ' if it is used in a string context or YYYYMMDD if it is used in a numeric context. There are two other functions that can be used instead of CURDATE() : CURRENT_DATE and CURRENT_DATE() .

What function finds the current time or date in MySQL?

MySQL NOW() Function The NOW() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS.

How do I query today's date in SQL?

To get the current date and time in SQL Server, use the GETDATE() function. This function returns a datetime data type; in other words, it contains both the date and the time, e.g. 2019-08-20 10:22:34 .


2 Answers

The fine manual has this to say about the NOW function:

mysql> SELECT NOW();         -> '2007-12-15 23:50:26' 

If you want just the date, then use CURDATE. The fine manual has this to say about the CURDATE function:

mysql> SELECT CURDATE();         -> '2008-06-13' 
like image 66
ta.speot.is Avatar answered Oct 28 '22 22:10

ta.speot.is


MySQL Date Functions The following table lists the most important built-in date functions in MySQL:

Function       Description NOW()      Returns the current date and time CURDATE()      Returns the current date CURTIME()      Returns the current time DATE()     Extracts the date part of a date or date/time expression EXTRACT()      Returns a single part of a date/time DATE_ADD()     Adds a specified time interval to a date DATE_SUB()     Subtracts a specified time interval from a date DATEDIFF()     Returns the number of days between two dates DATE_FORMAT()  Displays date/time data in different formats 

may be use full

SQL Date Data Types MySQL comes with the following data types for storing a date or a date/time value in the database:

DATE -       format YYYY-MM-DD DATETIME -   format: YYYY-MM-DD HH:MM:SS TIMESTAMP -  format: YYYY-MM-DD HH:MM:SS YEAR -       format YYYY or YY 

Example Query :

SELECT NOW();         Will Return '2007-12-15 23:50:26' 
like image 38
Imran Ali Khan Avatar answered Oct 28 '22 22:10

Imran Ali Khan