20 maj 2016

Formatowanie daty w mysql

SELECT
  e.name,
  DATE_FORMAT(FROM_UNIXTIME(start_time), '%Y-%d-%m') as start_date_format,
  DATE_FORMAT(FROM_UNIXTIME(start_time), '%H:%i:%S') as start_time_format,
  DATE_FORMAT(FROM_UNIXTIME(end_time), '%H:%i:%S') as end_time_format,
  TIMESTAMPDIFF(
    MINUTE,
    FROM_UNIXTIME(start_time),
    FROM_UNIXTIME(end_time)
  ) as diff_time_minutes_format,
  e.room_name,
  e.start_time,
  e.end_time,
WHERE
  e.room_id = r.id
  AND DATE_FORMAT(FROM_UNIXTIME(e.start_time), '%Y-%m-%d') <= '2016-05-23'
  AND DATE_FORMAT(FROM_UNIXTIME(e.end_time), '%Y-%m-%d') >= '2016-05-19'
  AND e.name in ('misiek')
ORDER BY
  e.start_time