在MySQL中将日期转换为毫秒 [英] Convert Date to Milliseconds in MySQL

查看:725
本文介绍了在MySQL中将日期转换为毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 MySQL 中的日期转换为 milliseconds 。这是我必须得到的日期:

I am trying to convert a date in MySQL to milliseconds. This is what I have to get the date:

DATE_ADD(mydate, INTERVAL(1-DAYOFWEEK(mydate)) DAY)

但是,如$ code> 15/02/2015 我想要得到那个日期的毫秒

But that returns me like 15/02/2015 and I want to get the milliseconds of that date.

推荐答案

使用UNIX_TIMESTAMP函数。

Use the UNIX_TIMESTAMP function.

SELECT(UNIX_TIMESTAMP(mydate)* 1000)FROM ...

UNIX_TIMESTAMP将获得秒数,您需要乘以1000才能获得毫秒。

UNIX_TIMESTAMP will get you seconds and you need to multiply by 1000 to get milliseconds.

要转换回来,请使用FROM_UNIXTIME()功能。

To convert back, use FROM_UNIXTIME() function.

SELECT FROM_UNIXTIME(date_in_milliseconds / 1000)FROM ...

再次,您需要除以1000才能在使用该功能之前将其取数秒。

Again, you need to divide by 1000 to get it to seconds before using the function.

这篇关于在MySQL中将日期转换为毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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