Hey, readers! In our previous article, we had understood the working of SQL Server DATEPART() function. In this article, we will be focusing on SQL Server GETDATE() function.

嘿,读者们! 在上一篇文章中,我们了解了SQL Server DATEPART()函数的工作原理 。 在本文中,我们将重点介绍SQL Server GETDATE()函数



SQL Server GETDATE()函数的工作 (Working of SQL Server GETDATE() function)

SQL GETDATE()function is used to fetch the current date and time from the system.

SQL GETDATE()函数用于从系统获取当前日期和时间

The GETDATE() function renders the below format while representing the current timestamp i.e. the current date and time.

GETDATE()函数在表示当前时间戳(即当前日期和时间)时呈现以下格式。

Having understood the working of SQL GETDATE() function, lets jump into understanding the syntax of the same.

了解了SQL GETDATE()函数的工作原理之后,我们就可以开始理解其语法。



SQL Server GETDATE()函数的语法 (Syntax of SQL Server GETDATE() function)

Unlike other SQL Date functions, the GETDATE() function does not accept any parameter. It does return the current date and time in the below format — YYYY-MM-DD hh:mm:ss.mmm.

与其他SQL Date函数不同,GETDATE()函数不接受任何参数。 它会以以下格式返回当前日期和时间— YYYY-MM-DD hh:mm:ss.mmm

Syntax:

句法:


GETDATE()

Now, let us understand the implementation of this function through various examples in the below section.

现在,让我们通过下一节中的各种示例来了解此功能的实现。



SQL Server GETDATE()函数的示例 (Examples of SQL Server GETDATE() function)

In the below example, we have used SQL SELECT statement along with GETDATE() function to display the current date and time.

在下面的示例中,我们使用了SQL SELECT statement以及GETDATE()函数来显示当前日期和时间。

Example 1:

范例1:


select GETDATE();

Output:

输出:


2020-06-05T15:14:39.967Z

Example 2:

范例2:

In this example, we have used SQL Server DATEPART() function wherein we have passed the interval to be extracted as ‘month‘ from the input date as the current date obtained through GETDATE() function as a parameter to the DATEDIFF() function.

在此示例中,我们使用了SQL Server DATEPART() function其中传递了要从输入日期中提取为“ month ”的间隔作为通过GETDATE() function获得的当前日期,作为DATEDIFF()函数的参数。


SELECT DATEPART(month, GETDATE()) AS Output;

Output:

输出:


6


GETDATE()v / s CURRENT_TIMESTAMP() (GETDATE() v/s CURRENT_TIMESTAMP())

While understanding the SQL Server Date Functions, we may come across the below question.

在理解SQL Server日期函数的同时,我们可能会遇到以下问题。

What’s the difference between GETDATE() function and CURRENT_TIMESTAMP() function, if both the functions return exactly the same value!?

如果两个函数返回的值完全相同,那么GETDATE()函数和CURRENT_TIMESTAMP()函数有什么区别?

Well, both functions have the same implementation. The only basic difference spotted is the origin of the functions i.e. CURRENT_TIMESTAMP() is an ANSI SQL function while GETDATE() is a T-SQL function.

嗯,这两个功能具有相同的实现。 发现的唯一基本区别是函数的来源,即CURRENT_TIMESTAMP()是ANSI SQL函数,而GETDATE()是T-SQL函数。



结论 (Conclusion)

By this, we have come to the end of this topic. Please feel free to comment below if you come across any doubts.

至此,我们到了本主题的结尾。 如果您有任何疑问,请随时在下面发表评论。

For more such posts on similar topics related to SQL Server, please do visit SQL Server JournalDev.

有关与SQL Server相关的类似主题的更多此类帖子,请访问SQL Server JournalDev 。



参考资料 (References)

  • SQL Server GETDATE() function — DocumentationSQL Server GETDATE()函数—文档

翻译自: https://www.journaldev.com/41024/sql-server-getdate

什么是SQL Server GETDATE()函数?相关推荐

  1. SQL Server CONVERT() 函数,Date 函数

    From: http://www.w3school.com.cn/sql/func_convert.asp 定义和用法 CONVERT() 函数是把日期转换为新数据类型的通用函数. CONVERT() ...

  2. SQL Server日期函数集合

    SQL Server日期函数集合--1:获取系统日期和时间值函数 --getdate() SELECT GETDATE() AS 'today' --getutcdate() SELECT GETUT ...

  3. sql server 自定义函数的使用

    sql server 自定义函数的使用 自定义函数 用户定义自定义函数像内置函数一样返回标量值,也可以将结果集用表格变量返回 用户自定义函数的类型: 标量函数:返回一个标量值 表格值函数{内联表格值函 ...

  4. Sql server 日期函数和日期转换

    时间函数 SQL Server Date 函数 下面的表格列出了 SQL Server 中最重要的内建日期函数: 函数 描述 GETDATE() 返回当前日期和时间 DATEPART(Type,dat ...

  5. oracle sql常用的函数,界别Oracle和SQL Server常用函数

    区分Oracle和SQL Server常用函数 一.数学函数 1.绝对值 S:select abs(-1) value O:select abs(-1) value from dual 2.取整(大) ...

  6. mysql coalesce函数用法,SQL Server COALESCE函数详解及实例

    SQL Server COALESCE函数详解 很多人知道ISNULL函数,但是很少人知道Coalesce函数,人们会无意中使用到Coalesce函数,并且发现它比ISNULL更加强大,其实到目前为止 ...

  7. SQL Server用户自定义函数

    用户自定义函数不能用于执行一系列改变数据库状态的操作,但它可以像系统 函 数一样在查询或存储过程等的程序段中使用,也可以像存储过程一样通过 EXECUTE 命令来执行.在 SQL Server 中根据 ...

  8. sql server charindex函数和patindex函数详解(转)

    charindex和patindex函数常常用来在一段字符中搜索字符或字符串.假如被搜索的字符中包含有要搜索的字符,那么这两个函数返回一个非零的整数,这个整数是要搜索的字符在被搜索的字符中的开始位数. ...

  9. Sql Server REPLACE函数的使用;SQL中 patindex函数的用法

    Sql Server REPLACE函数的使用 REPLACE 用第三个表达式替换第一个字符串表达式中出现的所有第二个给定字符串表达式. 语法 REPLACE ( ''string_replace1' ...

最新文章

  1. 计算机二级ms office excel,计算机二级Msoffice考试excel答案.docx
  2. UIAlertview改变按钮位置 大小
  3. tomcat常用的优化和配置
  4. 服务器监控报警系统软件设计,船舶机舱监控报警系统软件设计与实现
  5. java加锁多线程改为单线程_GUI为什么不设计为多线程(用户事件和底层事件的流程是相反的,每层都加锁效率太低,共用一把锁那就是单线程)...
  6. VC中char,TCHAR,WCHAR总结
  7. 【Zepto笔记】Zepto.js
  8. 写给初学asp.net的新人们 新手学习经验
  9. Servlet连接数据库
  10. Linux系统基础开发应用及Linux-C用户手册
  11. 你不可错过的Java学习资源清单
  12. Vue 使用 Echarts 显示热力地图信息
  13. MATLAB变压器设备故障模型,电力变压器内部故障简便仿真模型
  14. Preferences 是什么呢?
  15. 上海计算机一级考试理论,上海市计算机一级考试理论部分(上).doc
  16. 引用参数如何设缺省值(默认值)(C++)
  17. 【Java】认识Sring、String的常见操作和StringBuffer 和StringBuilder的区别【字符串详解】
  18. 论文的开题报告是什么样的?
  19. 股票和竞价以及股票的集合竞价是什么意思
  20. logo设计中配色有多重要

热门文章

  1. [转载]心灵丨愿你早一点发现,你才是自己最重要的粉丝
  2. [转载] Sublime Text 3 插件 ClangFormat 格式化 C/C++版
  3. [转载] Python学习笔记——用装饰器decorator和Memoization记忆化提高效率,原理讲清楚了
  4. 【pwnable.kr】passcode
  5. jsonp实现跨域问题
  6. SQL Server数据库partition by 与ROW_NUMBER()函数使用详解[转]
  7. Android系统中震动功能的测试
  8. OpenCV统计应用-CvHistogram直方图资料
  9. 高薪诚聘游戏引擎研发,有意者请与我联系!
  10. 数据结构上机实践第14周项目1(4) - 验证算法(平衡二叉树)