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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
博客园 - 【当耐特】
V
Visual Studio Blog
GbyAI
GbyAI
V
V2EX
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
B
Blog RSS Feed
量子位
MongoDB | Blog
MongoDB | Blog
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件

博客园 - 星答

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))

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