For test purpose I needed to populate a table field with random int number 0 and 1.
The RAND() function from mysql return numbers between 0 and 1 Continue Reading
For test purpose I needed to populate a table field with random int number 0 and 1.
The RAND() function from mysql return numbers between 0 and 1 Continue Reading
In order to select last month records you have to get first day of the last month and the last day of the first month. With this you use the mysql function BETWEEN.
Remember that current month could be January and the last month will in another year.
Finding first day of the last month:
DATE_FORMAT(CURRENT_DATE – INTERVAL 1 MONTH, "%Y-%m-01")
Finding the last thay of the last month:
LAST_DAY(CURRENT_DATE – INTERVAL 1 MONTH)
And the final Query is:
SELECT * FROM `my_table` `DATE` BETWEEN DATE_FORMAT(CURRENT_DATE – INTERVAL 1 MONTH, "%Y-%m-01") AND LAST_DAY(CURRENT_DATE – INTERVAL 1 MONTH)
Usually when you work with records where a date or time-stamp field is present you need to select records from:
Lets say you have a table (my_table) like this:
ID | Name | Date |
1 | Jon Dow | 2011-01-10 |
2 | Jane Dow | 2011-01-10 |
… | … | … |
where `Date` is date type fieldWatch movie online John Wick: Chapter 2 (2017)
Today records:
SELECT * FROM `my_table` WHERE `Date` = CURDATE()