100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 什么是SQL Server GETDATE()函数?

什么是SQL Server GETDATE()函数?

时间:2022-04-14 05:53:54

相关推荐

什么是SQL Server GETDATE()函数?

Hey, readers! In our previous article, we had understood the working of SQL Server DATEPART() function. In this article, we will be focusing onSQL 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 thecurrent date and timefrom 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 usedSQL SELECT statementalong with GETDATE() function to display the current date and time.

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

Example 1:

范例1:

select GETDATE();

Output:

输出:

-06-05T15:14:39.967Z

Example 2:

范例2:

In this example, we have usedSQL Server DATEPART() functionwherein we have passed the interval to be extracted as ‘month‘ from the input date as the current date obtained throughGETDATE() functionas 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 anANSI SQLfunction while GETDATE() is aT-SQLfunction.

嗯,这两个功能具有相同的实现。 发现的唯一基本区别是函数的来源,即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()函数—文档

翻译自: /41024/sql-server-getdate

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。