如何在sql中从date列获取月份和年份 [英] how to get month and year from date column in sql
本文介绍了如何在sql中从date列获取月份和年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从sql server 2014中的日期列获取月份和年份
2016-01-15 |
如何在sql server中的日期列中获取月份和年份
how to get month and year from date column in sql server 2014
Date |
2016-01-15 |
how to get month and year in date column in sql server
推荐答案
参见DATEPART(datepart,date) [ ^ ]
看看这个
Hi, check this out
select convert(char(4),year(getdate())) + convert(char(4),month(getdate()))
提示:只有字符可以与+标记组合,所以我们转换为int sting and combine
hint: only characters could combine with + mark so we convert int to sting and combine
尝试下面的SQL语法
try out below SQL syntax
SELECT
DATEADD(MONTH, DATEDIFF(MONTH, 0, <dateField>), 0) AS [year_month_date_field] FROM <your_table>
这篇关于如何在sql中从date列获取月份和年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文