dates.format_在SQL中使用DATES及其不同的内置函数NOW(),FORMAT()
dates.format
Basically, when we are working with dates, we need to be sure that the format of the date, we are trying to insert in the database is in format, and matches the format of the date column in the database.
基本上,當我們使用日期時,我們需要確保嘗試插入數據庫的日期格式為format,并且與數據庫中date列的格式匹配。
Sometimes, time gets complicated when it is involved in the database because our query will work accordingly as expected.
有時,涉及數據庫時,時間會變得很復雜,因為我們的查詢將按預期進行相應的工作。
MySQL:
MySQL:
DATE - format YYYY-MM-DD DATETIME - format: YYYY-MM-DD HH:MI:SS TIMESTAMP - format: YYYY-MM-DD HH:MI:SS YEAR - format YYYY or YYSQL Server:
SQL Server:
DATE - format YYYY-MM-DD DATETIME - format: YYYY-MM-DD HH:MI:SS SMALLDATETIME - format: YYYY-MM-DD HH:MI:SS TIMESTAMP - format: a unique numberSQL日期預定義函數 (SQL Dates pre-defined functions )
Some pre-defined functions are also present in SQL for dates are:
SQL中還存在一些針對日期的預定義函數:
NOW() and FORMAT() are scalar functions which return a single value, based in the input value.
NOW()和FORMAT()是標量函數,它們基于輸入值返回單個值。
NOW() function is used to Returns the current system date and time.
NOW()函數用于返回當前系統日期和時間。
SYNTAX:
句法:
SELECT NOW() FROM table_name;FORMAT() function is used to Formats how a field is to be displayed.
FORMAT()函數用于格式化字段的顯示方式。
SYNTAX:
句法:
SELECT FORMAT(column_name,format) FROM table_name;Column name and format parameter is required where format is used for specify the format.
如果使用format指定格式,則必須使用列名稱和format參數。
Similarly, we use these built-in functions:
同樣,我們使用以下內置函數:
CURDATE() function is used to proceed the current date in MySQL.
CURDATE()函數用于在MySQL中繼續當前日期。
CURTIME() function is used to take the current time in MySQL.
CURTIME()函數用于獲取MySQL中的當前時間。
DATE() function is used to extracts the date part of a date or date/time expressionin MySQL.
DATE()函數用于提取MySQL中日期或日期/時間表達式的日期部分。
EXTRACT() function is used to return a single part of a date and time in MySQL.
EXTRACT()函數用于在MySQL中返回日期和時間的單個部分。
DATE_ADD() function is used to add a specified time interval to a datein MySQL.
DATE_ADD()函數用于將指定的時間間隔添加到MySQL中的日期。
DATE SUB() function is used to subtract a specified time interval from a datein MySQL.
DATE SUB()函數用于從MySQL中的日期減去指定的時間間隔。
DATEDIFF() function is used to returns the number of days between two datesin MySQL and In SQL server it is used to add or subtract a specified time interval from a date.
DATEDIFF()函數用于返回MySQL中兩個日期之間的天數,而在SQL Server中則用于從日期中添加或減去指定的時間間隔。
DATE FORMAT() function is used to display the date or time in different formats in SQL Server.
DATE FORMAT()函數用于在SQL Server中以不同的格式顯示日期或時間。
GETDATE() function is used to return the current date and time in SQL Server.
GETDATE()函數用于返回SQL Server中的當前日期和時間。
DATEPART() function is used to returns a single part of a date/time in SQL Server.
DATEPART()函數用于在SQL Server中返回日期/時間的單個部分。
DATEADD() function is used to add or subtract a specified time interval from adate in SQL Server.
DATEADD()函數用于在SQL Server中的日期中添加或減去指定的時間間隔。
CONVERT() function is used to display the date or time in different formats in SQL Server.
CONVERT()函數用于在SQL Server中以不同的格式顯示日期或時間。
Conclusion:
結論:
In this article, we have learn how to use DATES and its built-in functions in SQL? Have a great day! Happy Learning!
在本文中,我們學習了如何在SQL中使用DATES及其內置函數 ? 祝你有美好的一天! 學習愉快!
翻譯自: https://www.includehelp.com/sql/Use-of-DATES-and-its-different-built-in-functions-NOW-FORMAT.aspx
dates.format
總結
以上是生活随笔為你收集整理的dates.format_在SQL中使用DATES及其不同的内置函数NOW(),FORMAT()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: “眇眇蛸挂网”下一句是什么
- 下一篇: Vestigium-Google Cod