MYSQL – datetime to seconds

If by “convert to seconds“, you mean “convert to an UNIX Timestamp(i.e. number of seconds since 1970-01-01), then you can use the UNIX_TIMESTAMP function :

select UNIX_TIMESTAMP(your_datetime_field)
from your_table
where ...

And, for the sake of completness, to convert from an Unix Timestamp to a datetime, you can use the FROM_UNIXTIME function.

Leave a Comment