Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract hour for MySQL FROM_UNIXTIME() results?

I have a column with time of measurments in timestamps in INT, and I need group data by interval of a hour. I already discovered MySQL function FROM_UNIXTIME(), but is there internal instrument in MySQL to extract hour from results of this function?

like image 217
Gill Bates Avatar asked Mar 11 '13 00:03

Gill Bates


People also ask

What does From_unixtime () function do?

MySQL FROM_UNIXTIME() function is used to return the date/datetime from a version of Unix timestamp. The format of return value would be either 'YYYY-MM-DD HH:MM:SS' or 'YYYYMMDDHHMMSS.

How do I count hours in MySQL?

MySQL HOUR() function MySQL HOUR() returns the HOUR of a time. The return value is within the range of 0 to 23 for time-of-day values. The range of time values may be larger than 23. Where time is a time.

Which function used to get the current time in MySQL?

CURRENT_TIME() function in MySQL is used to check the current time. It returns the current time as a value in 'hh:mm:ss' or hhmmss format, depending on whether the function is used in string or numeric context.

How do you write an hour in SQL?

The HOUR() function returns the hour part for a given date (from 0 to 838).


1 Answers

I think you mean FROM_UNIXTIME

GROUP BY
    DATE_FORMAT(FROM_UNIXTIME(time_column), '%Y %m %d %H'))
like image 81
Explosion Pills Avatar answered Oct 18 '22 10:10

Explosion Pills