ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

截取微软文档 Datetime SqlServer

2022-09-12 22:30:14  阅读:269  来源: 互联网

标签:datepart 截取 specified SqlServer value Datetime Returns time date


  1. sysdatetime
    sysdatetime()
    Returns a datetime2(7) value containing the date and time of the computer on which theinstance of SQL Server runs. The returned value doesn't includethe timezone offset.

  2. sysdatetimeoffset
    sysdatetimeoffset()
    Returns a datetimeoffset(7) value containing the dateand time of the computer on which the instance of SQL Server runs. The returned value includes thetime zone offset.

  3. SYSUTCDATETIME
    SYSUTCDATETIME()
    Returns a datetime2(7) value containing the date and time of the computer on which the instance of SQL Server is running. Thefunction returns the dateand time values as UTC time (Coordinated UniversalTime).

  4. CURRENT_TIMESTAMP
    CURRENT_TIMESTAMP
    Returns a datetime value containing the date and time of the computer on which the instance of SQL Server runs. The returned value doesn't include the time zone offset.

  5. GETDATE
    GETDATE()
    Returns a datetime value containing the date and time of the computer on which the instance of SQL Server runs. The returned value doesn't include the time zone offset.
    6.GETUTCDATE
    GETUTCDATE()
    Returns a datetime value containing the date and time of the computer on which the instance of SQL Server runs. The function returns the date and time values as UTC time (Coordinated UniversalTime).

datePart 缩写形式
day dd, d
week wk, ww
month mm, m
quarter qq, q
year yy, yyyy
hour hh
minute mi, n
second ss, s
millisecond ms
  1. DATE_BUCKET 待理解
    DATE_BUCKET(datepart, number, date, origin)
    Returns a value corresponding to the start of each date-time bucket from the timestamp defined by the origin parameter, or the default origin value of 1900-01-01 00:00:00.000 if the origin parameter isn't specified.

  2. DATENAME
    DATENAME ( datepart, date)
    Returns a character string representing the specified datepart of the specified date.
    获取时间的一部分。返回类型是字符串

  3. DATEPART
    DATEPART( datepart, date)
    Returns an integer representing the specified datepart of the specified date.
    同上,但是返回类型是数值

  4. DATETRUNC
    'DATETRUNC' 不是可以识别的 内置函数名称。
    DATETRUNC ( datepart, date)
    Returns an input date truncated to a specified datepart.

  5. DAY/MONTH/YEAR
    fun(date)
    Returns an integer representing the DAY/MONTH/YEAR part of the specified date.

  6. DATEFROMPARTS
    DATEFROMPARTS( year, month, day )
    Returns a date d value for the specified year, month, and day.

fractions:精度毫秒位的值
precision:精度
若精度为1,fraction单位为100ms,精度为2,单位为10ms,以此类推。

  1. DATETIME2FROMPARTS
    DATETIME2FROMPARTS( year, month, day, hour, minute, seconds, fractions, precision)
    Returns a datetime2 value for the specified date and time, with the specified precision.

  2. DATETIMEFROMPARTS
    DATETIMEFROMPARTS( year, month, day, hour, minute, seconds, milliseconds)
    Returns a datetime value for the specified date and time.

  3. DATETIMEOFFSETFROMPARTS
    DATETIMEOFFSETFROMPARTS( year, month, day, hour, minute, seconds, fractions, hour_offset, minute_offset, precision)
    Returns a datetimeoffset value for the specified date and time, with the specified offsets and precision.

  4. SMALLDATETIMEFROMPARTS
    SMALLDATETIMEFRO MPARTS( year, month, day, hour, minute)
    Returns a smalldatetime value for the specified date and time.

  5. TIMEFROMPARTS
    TIMEFROMPARTS( hour, minute, seconds, fractions, precision )
    Returns a time t value for thespecified time, with thespecified precision.

  6. DATEDIFF
    DATEDIFF ( datepart, startdate, enddate)
    根据datepart的基准比较两个时间的差值
    Returns the number of date or time datepart boundaries, crossed between two specified dates.

  7. DATEDIFF_BIG
    DATEDIFF_BIG ( datepart, startdate, enddate)
    同上,但返回值支持bigint
    Returns the number of date or time datepart boundaries, crossed between two specified dates.

  8. DATEADD
    DATEADD (datepart, number, date)
    Returns a new datetime value by adding an interval to the specified datepart of the specified date.

  9. EOMONTH
    EOMONTH ( start_date[, month_to_add ] )
    Returns the last day of the month containing the specified date, with an optional offset.

  10. SWITCHOFFSET
    SWITCHOFFSET (DATETIMEOFFSET, time_zone)
    SWITCHOFFSET changes the time zone offset of a DATETIMEOFFSET value, and preserves the UTC value.
    只改时区,不改时间

  11. TODATETIMEOFFSET
    TODATETIMEOFFSET (expression, time_zone)
    TODATETIMEOFFSET transforms a datetime2 value into a datetimeoffset value. TODATETIMEOFFSET interprets the datetime2 value in local time, for the specified time_zone.

标签:datepart,截取,specified,SqlServer,value,Datetime,Returns,time,date
来源: https://www.cnblogs.com/lwl1569/p/16685843.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有