[英]Is there an equivalent in SQL as microtime() for PHP?
I assumed there would be a query you can make in SQL for this, microtime() is derived from the server environment so I hoped there would be a 'like-for-like' in SQL, but I can't see it. 我假设会有一个可以在SQL中进行查询的查询,microtime()是从服务器环境派生的,所以我希望SQL中会出现“ like-for-like”,但我看不到。 Im using MSSQL but would be interested in other dbs too. 我正在使用MSSQL,但也会对其他数据库感兴趣。
Assuming MySQL, can you try something like this: 假设使用MySQL,您可以尝试以下方法吗:
SELECT UNIX_TIMESTAMP();
Here is the SQL Fiddle which also shows the use of MySQLs MicroSecond method. 这是SQL Fiddle ,它还显示了MySQL的MicroSecond方法的使用。
--EDIT - 编辑
Since you're using SQL Server, can this work: 由于您使用的是SQL Server,因此可以:
SELECT SYSDATETIME()
And the SQL Fiddle . 还有SQL Fiddle 。
select cast(datediff(second,'19700101',CURRENT_TIMESTAMP) as varchar)
+'.'+ cast(DATEPART(microsecond,CURRENT_TIMESTAMP) as varchar)
As of MYSQL 5.6.4 to emulate microtime()
you can use 从MYSQL 5.6.4开始,可以模拟microtime()
select concat(mod(unix_timestamp(now(6)),1),'00 ',unix_timestamp());
and to emulate microtime(true)
并模拟微时间microtime(true)
select concat(unix_timestamp(now(6)),'00');
The ' 00
' on both queries is there because MYSQL has a precision of only 6 digits. 因为MySQL的精度只有6位数字,所以两个查询都为' 00
'。 More info on https://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_now 有关https://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_now的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.