Mysql – How to store YMD, HM but not S Seconds in mariaDB/MySQL

datatypesdatetimemariadbMySQL

I was trying to make a column that stores the showtime of movies.

Since it is more meaningful to have showtimes in the unit of minutes, can I have a date type that has only years to minutes (eg. 2017-12-26 15:30), but no seconds? Thanks!

Best Answer

There is no special datatype for this :) Instead, you can use DATE_FORMAT

Example:

SELECT DATE_FORMAT(now(), '%Y-%m-%d %H:%i');

So you can create a view to converting your datetime column to the specific date format.

Create table with Datetime

create table test (date datetime);
insert into test values (now());
select * from test;
2017-12-28 10:30:24

Create view to convert date format

create view v_test as (select DATE_FORMAT(date, '%Y-%m-%d %H:%i'));

select * from v_test;
2017-12-28 10:30