mysql日期格式化

database

1select DATE_FORMAT(dtl.transdate,"%Y-%m-%d") as transdate,

2right(DATE_FORMAT(concat(transdate,transtime),"%Y-%m-%d %H:%i:%s"),8) as

3 transtime,dtl.custname,dtl.stuempno,dtl.deviceid,dtl.devtype,dev.devicename,a.names as areaname

4from t_devicedtl dtl

5leftjoin t_device dev on dev.deviceid=dtl.deviceid

6leftjoin t_area a on a.id=dev.areaid

 

  1. DATE_FORMAT(dtl.transdate,"%Y-%m-%d") :例如将数据库中的transdate字段20200123进行格式化,结果为:2020-01-23
  2. DATE_FORMAT(concat(transdate,transtime),"%Y-%m-%d %H:%i:%s"):例如字段transdate:20200123,字段transtime:122359,结果为:2020-01-23 12:23:59
  3. right(DATE_FORMAT(concat(transdate,transtime),"%Y-%m-%d %H:%i:%s"),8) :取格式化后取后8位,结果为:12:23:59

以上是 mysql日期格式化 的全部内容, 来源链接: utcz.com/z/534323.html

回到顶部