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 YY

SQL 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 number

SQL日期预定义函数 (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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/380536.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

砂.随笔.三

刚在整理电脑中的照片,把朋友们的照片都整进了"众生相",当点到他的照片时,迟疑了,没拉进去当剪切粘贴时,不知出了什么故障,"铛"地一声,"众生相"成了一空文件夹我不是一个容易觉得可惜的人,只是居然不禁窃喜适才没将他的照片放进去敲了敲脑袋,按住…

标志寄存器EFLAGES

EFLAGES是32位,对我们比较有用的是低16位 OF:溢出标志。溢出为1,否则为1DF:方向标志。串处理指令的方向IF:中断标志AF:辅助进位标志。进位时为1,否则为0ZF:零标志。运算结果为0时为1…

去除对象中的类型集合

一般来说,当某一个对象有多个集合类型的子元素时,我们都会给每个子元素创建一个集合对象来承载子元素,类似于: publicclassProcess {publicvar isExecutable:Boolean;publicvar refLaneSet:LaneSet;publicvar startEventList:Arra…

服务器安装centos6 linux,CentOS6.5安装详细教程,手把手教你安装Linux操作系统(CentOS6.5)...

CentOS6.5安装详细教程1、准备好CentOS-6.5.iso文件,并刻录到光盘中,放入光驱,重启服务器,修改BIOS为光驱启动,之后开始进入安装:2、按任意键,进入引导菜单。按上下键,移动光标&…

Vestigium-Google CodeJam 2020资格回合问题1解决方案

Problem statement: 问题陈述: Vestigium means "trace" in Latin. In this problem we work with Latin squares and matrix traces. Vestigium在拉丁语中表示“痕迹”。 在此问题中,我们使用拉丁方和矩阵迹线。 The trace of a square mat…

装修(43天,安装新家具啦)

装修(43天,安装新家具啦) 昨天保洁公司的来做了保洁.说好是9点钟让我去开门的,可他们却10点才到,原来听错地点了.三个人,从早上10开始做,到下午六点我去的时候,还没有做完,大概要做到七点.才150元钱,也真难为他们,还有一部分是公司的.效果觉得还是一般,有些地方还是不干净.可能…

dbms和sql_DBMS | 并发控制和各种并发控制方法

dbms和sql并发控制 (Concurrency Control) The concurrency control is the coordination of the simultaneous execution of a transaction in a multiuser database system. The concurrency control can ensure the serializability of the transaction in a multiuser data…

修改窗口图标 AfxRegisterWndClass()

LPCTSTR AFXAPI AfxRegisterWndClass(UINT nClassStyle,HCURSOR hCursor 0,HBRUSH hbrBackground 0,HICON hIcon 0 ); 可以简单修改一个窗口的注册类,当然也可以用SetWindowsLong()来实现。转载于:https://www.cnblogs.com/magic-cube/archive/2011/05/05/2038…

linux停止ssh服务的命令,开启、关闭、查看SSH服务

一、临时启用SSH服务1、通过SSH服务器的启动脚本文件启动SSH服务通过OpenSSH服务器的脚本文件“/etc/rc.d/init.d/sshd”启动SSH服务,命令执行如下。/etc/rc.d/init.d/sshd start命令执行后, SSH服务开始运行。2、使用Linux下的service命令启动SSH服务使…

XCHE命令

功能: 交换数据,交换两个操作数内容 形式: xche reg,reg xche reg,mem xche mem,regreg:寄存器;mem:内存单元 比如: xche eax,ebx;交换eax和ebx的内容 xche eax,[ebx]

软件测试经典网站(转)

软件测试经典网站网址简介http://bdonline.sqe.com/一个关于网站测试方面的网页,对这方面感兴趣的人可以参考http://citeseer.nj.nec.com/一个丰富的电子书库,内容很多,而且提供著作的相关文档参考和下载,是作者非常推荐的一个资料参考网站http://groups.yahoo.com/group/LoadR…

ai人工智能在手机的应用_强化学习在人工智能中的应用

ai人工智能在手机的应用The reinforcement learning is being used in many Intelligent Systems and the developers are seeing a great scope in it for current and future developments in the field of computers and robotics. This is because, the Reinforcement Lear…

LEA指令

功能:取偏移地址 格式: LEA reg,memreg:寄存器;mem:内存单元 例如: LEA AX,[1000H]将1000源操作数[1000H]的偏移地址1000H送到AX中。 理解的时候可将[]去掉,等同于: m…

参考站点

26个杰出的jQuery幻灯片插件http://woshao.com/article/6807a76a43d611e081e1000c2959fd2a/周公的专栏http://blog.csdn.net/zhoufoxcn/ W3SCHOOL在线教程http://www.w3school.com.cn/jQuery API 中文版http://www.css88.com/jqueryapi在ASP.NET中使用Highcharts js图表http://…

linux多进程通过中断实现,Linux驱动中断上下文中会发生什么结果实验测试

一、前言每一个Linux驱动工程师都知道这样一个准则:在中断上下文中不能睡眠。但是为什么interrupt context中不能调用导致睡眠的kernel API呢?如果驱动这么做会导致什么样的后果呢?这就是本文探讨的主题。为了理解这个主题,我们设…

'unsigned char'-C编程中的声明,赋值和用法

char is a data type in C programming language which can store value from -128 to 127. It generally used to store character values. char是C编程语言中的数据类型,可以存储从-128到127的值 。 它通常用于存储字符值。 unsigned is a qualifier which is us…

cmp指令

功能:比较 格式: CMP destination,sourceCMP 指令比较整数。字符代码也是整数,因此可以用 CMP 指令。 如果比较的是两个无符号数,则零标志位和进位标志位表示的两个操作数之间的关系 如果比较的是两个有符号数,则符…

游戏后的迷茫

9月份花了很多时间耐下心的玩了一个游戏——三国志11,这个是我继三国5以后耐下心玩得最多的一个游戏了,也是2年来耐下心玩得最多的游戏。现在是不是真的太浮躁了。连玩游戏都耐不下心。每天的泡论坛,看电影,下载,刻录的…

linux下获取时间的函数

相关函数 time,ctime,gmtime,localtime //--------------------------------------------------------------------------------------------------------------------------------------------------------// asctime(将时间和日…

linux 内核配置 dns,linux bind dns简单配置

操作系统版本:[roottest ~]# cat /etc/issueRed Hat Enterprise Linux AS release 4 (Nahant Update 4)Kernel r on an m内核:[roottest ~]# uname -aLinux test 2.6.9-42.EL #1 Wed Jul 12 23:16:43 EDT 2006 i686 i686 i386 GNU/Linux[roottest ~]#需要…