Convert datetime value into string

后端 未结 3 851
日久生厌
日久生厌 2020-12-01 09:08

I am fetching the current date & time using NOW() in mysql. I want to convert the date value into a varchar and concat it with another string. How do I do it?

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 09:32

    This is super old, but I figured I'd add my 2c. DATE_FORMAT does indeed return a string, but I was looking for the CAST function, in the situation that I already had a datetime string in the database and needed to pattern match against it:

    http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html

    In this case, you'd use:

    CAST(date_value AS char)

    This answers a slightly different question, but the question title seems ambiguous enough that this might help someone searching.

提交回复
热议问题