---
title: "SQL取系统种时间的方法"
author: "wtsoftware"
date: "2008-10-28T11:17:27Z"
tags: []
slug: "sql"
draft: false
lastmod: "2008-10-28T11:17:27Z"
id: 258867
url: "https://wtsoftware.iteye.com/blog/258867"
---

当前日期取年：select convert(char(4),getdate(),121)  

当前日期取月：select convert(char(7),getdate(),121) 

当前日期取日：select convert(char(10),getdate(),121) 

当前日期取周 
select datediff(day,'2008-1-1',getdate())/7

select （datediff(day,'2008-1-1',getdate())/7+1) 
或者select datepart(ww,getdate())都是获得当前是第几周，如果想知道今天星期几的话，就要得到上面的那个公司的余数。然后根据余数来判断。

这一年的第几周？
select datepart(ww,getdate())
select datename(ww,getdate())


转自:http://topic.csdn.net/u/20080805/10/ad85d999-ba0b-4834-904a-dd888d8638c6.html