从日起的dropdownlist得到周数 [英] get week number from date into dropdownlist

查看:128
本文介绍了从日起的dropdownlist得到周数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包含DateTime格式日期的一排数据库表。我需要做的就是让所有的可用日期的不同周数。例如,如果我有以下日期:

I have a database table containing a row of dates in DateTime format. what I need to do is get all the distinct weeks numbers of the available dates. for example if I have the following dates:

03-JAN-13 
04-JAN-13
09-JAN-13

SQL查询会给我接下来的几个星期的数字:1和2。
PS:事后我将投入一个DropDownList(与该步骤没有任何问题),这些值

the sql query would give me the following weeks numbers: 1 and 2. PS: afterwards I will put these values in a dropdownlist (no problem with that step).

所以有谁能够告诉我该怎么办呢?

So can anybody tell me how to do it?

推荐答案

您没有指定要使用,但你可以使用以下方法来得到周数是什么RDBMS。

You did not specify what RDBMS you are using but you could use the following to get week numbers.

SQL服务器你可以使用 DATEPART()

SQL Server you would use DatePart():

select distinct datepart(week, dates) WeekNo
from yourtable

请参阅 SQL拨弄演示

在MySQL中,你可以使用 周()

In MySQL you could use Week():

select distinct week(dates)
from yourtable

请参阅 SQL拨弄演示

在Oracle中,你可以使用 TO_CHAR()

In Oracle, you could use to_char():

select distinct to_char(dates, 'W') WeekNo
from yourtable

请参阅 SQL拨弄演示

在PostgreSQL里你可以使用以下内容:

In PostgreSQL you can use the following:

select distinct extract(WEEK from dates) WeekNO
from yourtable

请参阅 SQL拨弄演示

替换 yourtable 与您的表名和日期您的日期列。

Replace the yourtable with your table name and dates with your date column.

编辑#1:如果您正在使用的MS Access,那么你仍然可以使用的 DATEPART() (这是在MS Access 2003中测试过):

Edit #1: If you are using MS Access then you can still use DatePart() (this was tested in MS Access 2003):

SELECT distinct datepart("ww", dates) as WeekNo
FROM yourtable;

这篇关于从日起的dropdownlist得到周数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆