separate Date and Time

1

I have the following with the datetime format

create table tabla
  (
    f_inicial date not null ,
    f_final date not null ,
    c_almacen varchar (250),
    sw_costo smallint,
    sw_consulta smallint,
    usuario char(30) not null,
    sw_genera_consulta smallint,
     ts_creacion datetime year to fraction(3)
        default current year to fraction(3)
  );

I need to separate the date and time in the ts_creation field

usuario                        ts_creacion    
ct060901                       2017-06-15 10:29:00.000
ct060901                       2017-06-15 10:34:08.000
    
asked by Norbey Martinez 15.06.2017 в 23:27
source

3 answers

4

These are some of the options you can use:

SELECT DATE_FORMAT(ts_creacion, '%Y-%m-%d') FechaStr, 
       DATE_FORMAT(ts_creacion,'%H:%i:%s')  HoraStr,
       DATE(ts_creacion)  Fecha,
       TIME(ts_creacion)  Hora
       FROM tabla
    
answered by 15.06.2017 в 23:33
0

There are several ways but the one I use the most is like this ...

select   LEFT((ts_creacion),10) AS fecha, RIGHT((ts_creacion),8) as hora from tabla
    
answered by 15.06.2017 в 23:30
0

How about the function HOUR (datetime) :

SELECT HOUR(ts_creacion) from tabla

Or TIME (datetime) that you it is returned by the hour, minute and second:

SELECT TIME(ts_creacion)
    
answered by 15.06.2017 в 23:31