Convert datetime value into string

后端 未结 3 845
日久生厌
日久生厌 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:30

    Try this:

    concat(left(datefield,10),left(timefield,8))
    
    • 10 char on date field based on full date yyyy-MM-dd.

    • 8 char on time field based on full time hh:mm:ss.

    It depends on the format you want it. normally you can use script above and you can concat another field or string as you want it.

    Because actually date and time field tread as string if you read it. But of course you will got error while update or insert it.

提交回复
热议问题