如何获取当前datetime在SQL? [英] how to get current datetime in SQL?

查看:551
本文介绍了如何获取当前datetime在SQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望获取当前datetime以插入到lastModifiedTime列。我使用MySQL数据库。我的问题是:


  1. SQL中有可用的函数吗?或


  2. 它是实现依赖的,因此每个数据库都有自己的功能。


  3. MySQL中可用的函数是什么?



解决方案

/ p>

1。在SQL中是否有可用的函数?

是的,SQL 92规范,10月97日, 171,第6.16节规定了这个功能:

  CURRENT_TIME评估时刻的日期时间
CURRENT_DATE评估时的日期
CURRENT_TIMESTAMP日期&评估时的时间

2。它是实现依赖的,因此每个数据库都有自己的函数为此?

每个数据库都有自己的实现,但他们必须实现上面的三个函数,如果它们符合SQL 92规范但取决于规格的版本)



3。在MySQL中可用的功能是什么?

  NOW()返回2009-08-05 15:13:00 
CURDATE()返回2009-08-05
CURTIME()返回15:13:00

(如SixFootTallRabbit所说)


Want to get current datetime to insert into lastModifiedTime column. I am using MySQL database. My questions are:

  1. is there a function available in SQL? or

  2. it is implementation depended so each database has its own function for this?

  3. what is the function available in MySQL?

解决方案

Complete answer:

1. Is there a function available in SQL?
Yes, the SQL 92 spec, Oct 97, pg. 171, section 6.16 specifies this functions:

CURRENT_TIME       Time of day at moment of evaluation
CURRENT_DATE       Date at moment of evaluation
CURRENT_TIMESTAMP  Date & Time at moment of evaluation

2. It is implementation depended so each database has its own function for this?
Each database has its own implementations, but they have to implement the three function above if they comply with the SQL 92 specification (but depends on the version of the spec)

3. What is the function available in MySQL?

NOW() returns 2009-08-05 15:13:00  
CURDATE() returns 2009-08-05  
CURTIME() returns 15:13:00  

(As SixFootTallRabbit says)

这篇关于如何获取当前datetime在SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆