How to select only date from a DATETIME field in MySQL?

前端 未结 16 1930
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 04:37

I have a table in the MySQL database that is set up with DATETIME. I need to SELECT in this table only by DATE and excluding the time.

How d

相关标签:
16条回答
  • 2020-11-28 04:44

    SELECT DATE(ColumnName) FROM tablename;

    More on MySQL DATE() function.

    0 讨论(0)
  • 2020-11-28 04:45

    Please try this answer.

    SELECT * FROM `Yourtable` WHERE date(`dateField`) = '2018-09-25'
    
    0 讨论(0)
  • 2020-11-28 04:47

    In MYSQL we have function called DATE_FORMAT(date,format). In your case your select statement will become like this:-

    SELECT DATE_FORMAT(dateTimeFieldName,"%a%m%Y") as dateFieldName FROM table_name

    For more information about Mysql DATE and TIME functions click here.

    0 讨论(0)
  • 2020-11-28 04:47

    Try SELECT * FROM Profiles WHERE date(DateReg)=$date where $date is in yyyy-mm-dd

    Alternatively SELECT * FROM Profiles WHERE left(DateReg,10)=$date

    Cheers

    0 讨论(0)
  • 2020-11-28 04:48

    Use DATE_FORMAT

    select DATE_FORMAT(date,'%d') from tablename =>Date only
    

    example:

    select DATE_FORMAT(`date_column`,'%d') from `database_name`.`table_name`;
    
    0 讨论(0)
  • 2020-11-28 04:50

    In the interest of actually putting a working solution to this question:

    SELECT ... WHERE `myDateColumn` >= DATE(DATE_FORMAT(NOW(),'%Y-%m-%d'));
    

    Obviously, you could change the NOW() function to any date or variable you want.

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