截取微软文档 Datetime SqlServer

2022/9/14 2:18:28

本文主要是介绍截取微软文档 Datetime SqlServer,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

  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.



这篇关于截取微软文档 Datetime SqlServer的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程