Selecting date range MySQL with date_format

前端 未结 2 2086
逝去的感伤
逝去的感伤 2020-12-30 11:18

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-%         


        
相关标签:
2条回答
  • 2020-12-30 11:53
    SELECT MvtDate,date_format(MvtDate,'%d-%m-%Y')
      FROM (`immmvt`)
     WHERE date_format(MvtDate,'%d-%m-%Y') IN ('01-01-2010', '02-01-2010')
    
    0 讨论(0)
  • 2020-12-30 11:56

    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
    
    0 讨论(0)
提交回复
热议问题