//如果你使用的是SQL Server数据库,请参考如下帮助DATEPART
返回代表指定日期的指定日期部分的整数。语法
DATEPART ( datepart , date ) 参数
datepart是指定应返回的日期部分的参数。下表列出了 Microsoft® SQL Server™ 识别的日期部分和缩写。日期部分 缩写 
year yy, yyyy 
quarter qq, q 
month mm, m 
dayofyear dy, y 
day dd, d 
week wk, ww 
weekday dw 
Hour hh 
minute mi, n 
second ss, s 
millisecond ms 
week (wk, ww) 日期部分反映对 SET DATEFIRST 作的更改。任何一年的 1 月 1 日定义了 week 日期部分的开始数字,例如:DATEPART(wk, 'Jan 1, xxxx') = 1,此处 xxxx 代表任一年。weekday (dw) 日期部分返回对应于星期中的某天的数,例如:Sunday = 1、Saturday = 7。weekday 日期部分产生的数取决于 SET DATEFIRST 设定的值,此命令设定星期中的第一天。date是返回 datetime 或 smalldatetime 值或日期格式字符串的表达式。对 1753 年 1 月 1 日之后的日期用datetime 数据类型。更早的日期存储为字符数据。当输入 datetime 值时,始终将其放入引号中。因为 smalldatetime 只精确到分钟,所以当用 smalldatetime 值时,秒和毫秒总是 0。如果只指定年份的最后两位数字,则小于或等于"两位数年份截止期"配置选项的值的最后两位数字的数字所在世纪与截止年所在世纪相同。大于该选项的值的最后两位数字的数字所在世纪为截止年所在世纪的前一个世纪。例如,如果 two digit year cutoff 为 2049 (默认),则 49 被解释为 2049,2050 被解释为 1950。为避免模糊,请使用四位数的年份。有关时间值指定的更多信息,请参见时间格式。有关日期指定的更多信息,请参见 datetime 和 smalldatetime。 返回类型
int注释
DAY、MONTH、和 YEAR 函数分别是 DATEPART(dd, date)、DATEPART(mm, date)、和 DATEPART(yy, date) 的同义词。示例
GETDATE 函数返回当前日期;然而,比较时并不总是需要完整的日期信息(通常只是对日期的一部分进行比较)。此示例显示 GETDATE 及 DATEPART 的输出。SELECT GETDATE() AS 'Current Date'
GO下面是结果集:Current Date                
--------------------------- 
Feb 18 1998 11:46PM         SELECT DATEPART(month, GETDATE()) AS 'Month Number'
GO下面是结果集:Month Number 
------------ 
2            此示例假设日期是 5 月 29 日。SELECT DATEPART(month, GETDATE())
GO下面是结果集:----------- 
5           (1 row(s) affected)在此示例中,以数字表示日期。注意:SQL Server 将 0 解释为 01/01/1900。SELECT DATEPART(m, 0), DATEPART(d, 0), DATEPART(yy, 0)下面是结果集:----- ------ ------
1     1      1900

解决方案 »

  1.   

    update 表名
    set myweek = DATEPART(ww, mydate)
         
    --执行之间看看是不是你要的
    select mydate,DATEPART(ww, mydate)
    from 表名
      

  2.   

    用 API:   DayOfWeek(Date: TDateTime):Integer; 看看返回的是一integer值   星期一:1, 星期日: 7(依次类推)
      

  3.   

    to :zswang(伴水):
     set myweek = DATEPART(ww, mydate)
    'ww'是指什么参数?
      

  4.   

    注意,星期是从日开始的。
    update 表名
    set myweek = datepart(weekday,dateadd(dd,-1,mydate))
      

  5.   

    你的数据库是不是冗余了,既有日期,便不需要特别指出星期,因为想要提取星期几的话,如下代码可实现:
    Edit1.Text:=FormatDateTime('YYYY-MM-DD ddd',strtodate(str));
    其中str为该日期字段值,小写ddd 便可实现星期几
      

  6.   

    对,晚了!
    : Xinhao() 的方法不错!数据库的确冗余了,少量应用倒无所谓,若大型数据库,这些都至关重要,且规范化也就差了
      

  7.   

    FormatDateTime('YYYY-MM-DD mmm',strtodate(mydate));
      

  8.   

    to sprinou:
    “ww”就想是“select”这样的关键字,是系统预先设置好的
    “week(星期)”的简称
    你可以看看上面的帮助(最好自己学会到SQL Server中看Help)
    其他的知识自己在去学习
    我还不知道这个问题解决没有?
      

  9.   

    DATEPART(datepart, date)Arguments
    datepart 
    Is the parameter that specifies the part of the date to return. The table lists dateparts and abbreviations recognized by Microsoft® SQL Server™. 
     Datepart Abbreviations 
    year yy, yyyy 
    quarter qq, q 
    month mm, m 
    dayofyear dy, y 
    day dd, d 
    week wk, ww 
    weekday dw 
    hour hh 
    minute mi, n 
    second ss, s 
    millisecond ms 
    The week (wk, ww) datepart reflects changes made to SET DATEFIRST. January 1 of any year defines the starting number for the week datepart, for example: DATEPART(wk, ‘Jan 1, xxxx’) = 1, where xxxx is any year. The weekday (dw) datepart returns a number that corresponds to the day of the week, for example: Sunday = 1, Saturday = 7. The number produced by the weekday datepart depends on the value set by SET DATEFIRST, which sets the first day of the week. date 
    Is an expression that returns a datetime or smalldatetime value, or a character string in a date format. Use the datetime data type only for dates after January 1, 1753. Store dates as character data for earlier dates. When entering datetime values, always enclose them in quotation s. Because smalldatetime is accurate only to the minute, when a smalldatetime value is used, seconds and milliseconds are always 0. 
    If you specify only the last two digits of the year, values that are less than or equal to the last two digits of the value of the two digit year cutoff configuration option are in the same century as the cutoff year. Values that are greater than the last two digits of the value of this option are in the century that precedes the cutoff year. For example, if two digit year cutoff is 2049 (default), 49 is interpreted as 2049 and 2050 is interpreted as 1950. To avoid ambiguity, use four-digit years. For information about specifying time values, see Time Formats. For information about specifying dates, see datetime and smalldatetime. Return Types
    int
      

  10.   

    DayOfWeek函数:定义:function DayOfWeek(Date: TDateTime): Integer;作用:得到指定日期的星期值,返回1~7,代表周日到周六。希望对你有所帮助