Sql Ansi to manage DateTime values

北城余情 提交于 2020-01-05 10:32:04

问题


I'm developing a multi-database system.
I want the difference between two dates in seconds.

In SQL Server I got:
DATEDIFF(second,stardate,enddate)
In MySql:
TIME_TO_SEC(TIMEDIFF(stardate,enddate))

My question:
Does Sql Ansi have functions to manage DateTime values?
i.e.: There are datetime functions generic for all databases?


回答1:


According to SQL:1999, date1-date0 should give you a value of type INTERVAL, a struct from which you should be able to extract YEAR, MONTH, DAY, etc.

I've never used it and I don't think it's widely supported (though I may not be up-to-date). If you're doing time arithmetic in the database layer and you want to be cross-DBMS compatible the usual solution is simply to use integer timestamps (of whatever resolution, but Unix time is common) and plain old integer arithmetic which is completely reliable cross-platform.



来源:https://stackoverflow.com/questions/449182/sql-ansi-to-manage-datetime-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!