Home > Database > Mysql Tutorial > body text

SQL将datetime转化为字符串并截取字符串

WBOY
Release: 2016-06-07 17:29:23
Original
1654 people have browsed it

select sr_child as

select sr_child as '孩子姓名', sr_parents as '家长姓名' ,ss_updatetime as '分配时间', left(ss_updatetime,CHARINDEX(' ',ss_updatetime)-1),SUBSTRING(CONVERT(CHAR(19), ss_updatetime, 120),1,10)as '转换格式并截取后的时间'from dbo.tb_sell_resources,dbo.tb_sell_selldetails where sr_id = ss_rsid and ss_qdstate 1 order by ss_updatetime

 

 

sql 中字符串截取函数: SUBSTRING(name,start,end)

name: 字符串格式的 字段名

start: 规定开始位置(起始值是 1)

end:截取字符串结束的位置

 

sql 中Datetime格式转换为字符串格式: 2000-01-01 01:01:01(Datetime) CONVERT(CHAR(19), CURRENT_TIMESTAMP, 120)

CURRENT_TIMESTAMP: 当前时间(此处可以写Datetime格式的字段名,,例如ss_updatetime)

其余的参数(CHAR(19), 120等)不用修改

使用之后 2000-01-01 01:01:01(Datetime)变为 2000-01-01 01:01:01(字符串格式)

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template