I've got an issue selecting a date range with MySQL.
SELECT MvtDate,date_format(MvtDate,'%d-%m-%Y')
FROM (`immmvt`)
WHERE date_format(MvtDate,'%d-%m-%Y') BETWEEN '01-01-2010' AND '02-01-2010'
mvtDate
type is date like 2010-01-01 00:00:00
.
When I run the query, the result works for the days and the months but it also show me other result from other years.
Like 01-01-2011
etc.
How to Select rows from a range of dates with MySQL query command. If you need to select rows from a MySQL database' table in a date range, you need to use a command like this: SELECT * FROM table WHERE date_column >= '2014-01-01' AND date_column <= '2015-01-01';
The following is the output. The following is the query to format the date to YYYY-MM-DD. mysql> select str_to_date(LoginDate,'%d. %m.
Use the DATEDIFF() function to retrieve the number of days between two dates in a MySQL database.
MySQL WEEKDAY() Function The WEEKDAY() function returns the weekday number for a given date. Note: 0 = Monday, 1 = Tuesday, 2 = Wednesday, 3 = Thursday, 4 = Friday, 5 = Saturday, 6 = Sunday.
You should use STR_TO_DATE
since you want to convert string
back to date
SELECT MvtDate, date_format(MvtDate,'%d-%m-%Y')
FROM `immmvt`
WHERE MvtDate BETWEEN STR_TO_DATE('01-01-2010','%d-%m-%Y') AND
STR_TO_DATE('02-01-2010','%d-%m-%Y')
FYI: DATE_FORMAT() converts date to formatted string representation. STR_TO_DATE() converts formatted string back to date
SELECT MvtDate,date_format(MvtDate,'%d-%m-%Y')
FROM (`immmvt`)
WHERE date_format(MvtDate,'%d-%m-%Y') IN ('01-01-2010', '02-01-2010')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With