简体   繁体   English

如何将SQL Server SMALLDATETIME转换为Unix时间戳?

[英]How do I convert an SQL Server SMALLDATETIME to a Unix timestamp?

How do I convert an SQL Server SMALLDATETIME to Unix Timestamp? 如何将SQL Server SMALLDATETIME转换为Unix时间戳?

date was stored as CAST(0x96040474 AS SmallDateTime) in MS Access DB. 日期在MS Access DB中存储为CAST(0x96040474 AS SmallDateTime)。 Data was dumped to SQL and I'm looking to convert those times to Unix Timestamps for MySQL. 数据被转储到SQL,我希望将这些时间转换为MySQL的Unix时间戳。

Thanks AO 谢谢AO

select datediff(ss, '1/1/1970', your_date_here) 选择datediff(ss,'1/1/1970',your_date_here)

eg 例如

select datediff(ss, '1/1/1970', cast('1/1/1989' as smalldatetime)) 选择datediff(ss,'1/1/1970',演员('1/1/1989'作为smalldatetime))

PHP的strtotime()函数将使用smalldatetime作为参数。

From SQL Server 2005 Books Online , "Transact SQL Reference" SQL Server 2005联机丛书中 ,“Transact SQL Reference”

The Database Engine stores smalldatetime values as two 2-byte integers. 数据库引擎将smalldatetime值存储为两个2字节整数。 The first 2 bytes store the number of days after January 1, 1900. The other 2 bytes store the number of minutes since midnight. 前2个字节存储1900年1月1日之后的天数。其他2个字节存储自午夜以来的分钟数。

So it looks like you need to do some splitting of the hex values into two integers and convert from a 1900/01/01 base date to a 1970/01/01 base date, then take the other integer as integral minutes past midnight. 所以看起来你需要将十六进制值分成两个整数并从1900/01/01基准日期转换为1970/01/01基准日期,然后将另一个整数作为整数分钟过午夜。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM