Breaking up query fields

Asked

Viewed 36 times

1

I’m doing a search with mysql, where the return is a field DATE, I need to dismember this field in DAY, MONTH, HOUR, SECONDS and put each one within a variable, I’m not able to do this, I tried to do for a query but this returning

Resource id #18

Resource id #19

The query I made is as follows::

SELECT DATE(DAT_EHORA_EVENT) FROM tbl_CLIENTES_AGENDA WHERE COD_SEQUN_AGEND = '".$linha['COD_SEQUN_AGEND']."'

1 answer

1


Solution in MySQL

SELECT YEAR(DAT_EHORA_EVENT), 
       MONTH(DAT_EHORA_EVENT), 
       DAYOFMONTH(DAT_EHORA_EVENT), 
       HOUR(DAT_EHORA_EVENT), 
       MINUTE(DAT_EHORA_EVENT), 
       SECOND(DAT_EHORA_EVENT)
FROM tbl_CLIENTES_AGENDA WHERE COD_SEQUN_AGEND = '".$linha['COD_SEQUN_AGEND']."'

Solution in PHP

$hora = strtotime($row["DAT_EHORA_EVENT"]);
echo date('Y', $hora); // ano
echo date('m', $hora); // mês
echo date('d', $hora); // dia
echo date('h', $hora); // hora
echo date('i', $hora); // minuto
echo date('s', $hora); // segundo
  • And to reverse the date like it really does ?

  • Because it comes YYYY-MM-DD ?

  • You say format to dd/MM/yyyy?

  • Comes like this because it is formatting inside Mysql

  • that, exactly more already get.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.