转换例如2012年5月25日至1970年1月1日以来的秒数 [英] Convert eg. 2012-05-25 to seconds since January 1 1970

查看:113
本文介绍了转换例如2012年5月25日至1970年1月1日以来的秒数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,可以从php中将时间另存为 time(),这是自 1970年1月1日。

I have a database where I save time as time() from php, which is seconds since 1 jan 1970.

有什么我可以转换的方法,例如 2012-12-12 1970年1月1日

Is there any way I can convert, for example 2012-12-12 to seconds since 1 jan 1970?

我想这样做:

SELECT * 
FROM Table 
WHERE date > '2012-11-30' AND date < '2012-12-30'

这甚至有可能吗?

(我想在没有任何php date()的情况下做到这一点)

(I would like to do it without any php date())

推荐答案

DATEDIFF 将成为您的朋友此处:

DATEDIFF is going to be your friend here:

select datediff(s, '1970-01-01', '2012-12-12') as SecondsSinceEpoch

请注意,由于datediff返回一个整数,因此您可以将最大日期时间(以秒为单位)与1月1日进行比较, 1970是 2038-01-19 03:14:07

Note that because datediff returns an int, the maximum datetime you can compare (using seconds) with Jan 1st, 1970 is 2038-01-19 03:14:07.

这篇关于转换例如2012年5月25日至1970年1月1日以来的秒数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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