Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: using YEAR_MONTH

phpmyAdmin suggested an autocompleted function YEAR_MONTH() in the Query Editor that I can't find anywhere online. It would be awesome if this function existed.

Does it? If yes, how would one use it?

like image 933
BassMHL Avatar asked Jan 20 '16 17:01

BassMHL


People also ask

How use now function in MySQL?

NOW() function in MYSQL This function in MySQL is used to check the current date and time value. The return type for NOW() function is either in 'YYYY-MM-DD HH:MM:SS' format or YYYYMMDDHHMMSS. uuuuuu format, depending on whether the function is used in a string or numeric context.

How do I get previous month records in MySQL?

Similarly, if you want to get records for past one month rolling, that is, last 30 days, then here's the SQL query for it. select * from orders where order_date>now() - interval 1 month; In the above query, we select rows after past 1 month interval.

Which function used to get the current time 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.


1 Answers

While it isn't a valid function, YEAR_MONTH is valid SQL. For instance:

SELECT EXTRACT(YEAR_MONTH FROM '2009-07-02 01:02:03');

See also the discussion at https://github.com/phpmyadmin/phpmyadmin/issues/11877

like image 168
Isaac Bennetch Avatar answered Sep 26 '22 19:09

Isaac Bennetch