惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
B
Blog RSS Feed
H
Help Net Security
Blog — PlanetScale
Blog — PlanetScale
Vercel News
Vercel News
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
L
LangChain Blog
IT之家
IT之家
F
Fortinet All Blogs
V
V2EX
C
Check Point Blog
The Cloudflare Blog
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
A
About on SuperTechFans

博客园 - 星答

win7 小版本号16384( 最终测试版) 两个参数互换(不用第三个变量) c#实现九九乘法表 Excel导入导出 24券 域名 .net 6年之感想 服务器配置之DNS .net 杂记 asp.net 导出CSV Powerdesigner反向工程 无任何网络提供程序接受指定的网络路径 虚拟机拖拽 sql表的所有者 奥运门票有了 阿泰斯特乘火箭 sql脚本导入Powerdesigner C# 上传文件 - 星答 - 博客园 'f_split' 不是可以识别的 函数名 加载App_Licenses出错
常用时间函数
星答 · 2010-06-08 · via 博客园 - 星答

方法一:

convert

CONVERT(data_type,expression[,style])
第1个参数为,转换后的大小,第2个为转换日期的字段或函数,第3个为转换的格式

例如:取得当然日期,用年-月-日的格式显示

select convert(varchar(10),getdate(),120)

varchar(10)表示转换后的长度为10

120表示24(yyyy-mm-dd hh:mi:ss)小时制的odbc规范

显示结果为:2010-06-08

方法二:

cast

select cast(year(getdate()) as varchar(12))
select cast(month(getdate()) as varchar(12))
select cast(day(getdate()) as varchar(12))

分别取出年,月,日,拼成一个字符串