T
T
Testin2014-03-12 23:35:49
MySQL
Testin, 2014-03-12 23:35:49

How to convert MySQL timestamp to seconds?

There is a timestamp field in MySQL 5.5.35. But when fetching, it returns not a date in seconds, but a date like "2014-03-06 15:22:21". It also shows up in phpMyAdmin.
Data is obtained using ORM (Kohana).
How it is possible to receive by default in seconds?
Or store in int?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
svd71, 2014-03-12
@svd71

try like this:
SELECT UNIX_TIMESTAMP('2014-03-06 15:22:21');

V
Vampiro, 2014-03-13
@Vampiro

php.net/strtotime

A
Alexey, 2014-03-14
@AmberLEX

1. If you need in seconds, you can store unsigned NULL in int (10) (in the standard dump for the authorization module, the created and updated values
​​\u200b\u200bare stored in this way ) here )
3. Look here - I think you will find what you need, I wrote in more detail for the dates.

D
Denis Kotlyarov, 2015-07-17
@denisandroid

Use strtotime, in php, but it needs to be in Ymd H:i:s format.
For example:
$time='2015-07-17 17:06:29';
$time=strtotime(date('Ymd H:i:s')) - strtotime($time);
And it turns out that we will find out the difference, how many seconds have passed since the date that is in $time (in your case, there is a date from mysql).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question