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

发布于 2024-07-08 21:46:28 字数 178 浏览 10 评论 0原文

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

日期在 MS Access DB 中存储为 CAST(0x96040474 AS SmallDateTime)。 数据被转储到 SQL,我希望将这些时间转换为 MySQL 的 Unix 时间戳。

谢谢 AO

How do I convert an SQL Server SMALLDATETIME to Unix Timestamp?

date was stored as CAST(0x96040474 AS SmallDateTime) in MS Access DB. Data was dumped to SQL and I'm looking to convert those times to Unix Timestamps for MySQL.

Thanks
AO

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

地狱即天堂 2024-07-15 21:46:28

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

例如

select datediff(ss, '1/1/1970',cast('1/1/1989' assmalldatetime))

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

e.g.

select datediff(ss, '1/1/1970', cast('1/1/1989' as smalldatetime))

夜光 2024-07-15 21:46:28

来自SQL Server 2005 联机丛书,“Transact SQL 参考”

数据库引擎将 smalldatetime 值存储为两个 2 字节整数。 前 2 个字节存储 1900 年 1 月 1 日之后的天数。另外 2 个字节存储自午夜以来的分钟数。

因此,您似乎需要将十六进制值拆分为两个整数,并将 1900/01/01 基准日期转换为 1970/01/01 基准日期,然后将另一个整数作为午夜过后的整数分钟。

From SQL Server 2005 Books Online, "Transact SQL Reference"

The Database Engine stores smalldatetime values as two 2-byte integers. The first 2 bytes store the number of days after January 1, 1900. The other 2 bytes store the number of minutes since midnight.

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.

灯下孤影 2024-07-15 21:46:28

PHP 的 strtotime() 函数将采用小日期时间作为参数。

PHP's strtotime() function will take a smalldatetime as an argument.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文