Mysql strip time component from datetime

前端 未结 5 915
夕颜
夕颜 2020-12-03 00:20

I need to do a date comparison in Mysql without taking into account the time component i.e. i need to convert \'2008-11-05 14:30:00\' to \'2008-11-05\'

Currently i a

相关标签:
5条回答
  • 2020-12-03 00:46

    Yes, use the date function:

    SELECT date(my_date)
    
    0 讨论(0)
  • 2020-12-03 00:50

    Just a simple way of doing it date("d F Y",strtotime($row['date'])) where $row['date'] comes from your query

    0 讨论(0)
  • 2020-12-03 00:55

    select date(somedate) is the most common.

    If you need to accommodate other formats, you can use:

    SELECT DATE_FORMAT(your_date, '%Y-%m-%d');
    
    0 讨论(0)
  • 2020-12-03 01:01

    You could use ToShortDateString();

    0 讨论(0)
  • 2020-12-03 01:08

    In PostgreSQL you use the TRUNC() function, but I'm not seeing it for MySQL. From my brief Googling, it looks like you'll need to cast your DATETIME value to be just DATE.

    date_col = CAST(NOW() AS DATE)
    

    See http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html

    0 讨论(0)
提交回复
热议问题