How to format / separate date and time from a datetime field of sqlite

2

I have the Postings table with the following fields:

CREATE TABLE [LANCAMENTO](
  [ID] INTEGER PRIMARY KEY ASC AUTOINCREMENT NOT NULL UNIQUE, 
  [VALOR] DECIMAL(8, 2), 
  [DATE_BUY] DATETIME, 
  [DESCRIPTION] VARCHAR(150), 
  [TYPE_RELEASE] VARCHAR(1), 
  [ORGANIZATION] VARCHAR(50), 
  [ID_USUARIO] INTEGER NOT NULL REFERENCES USUARIOS([ID]));

I want to know how to paste submit Time or Date of the DATE_BUY field.

    
asked by anonymous 14.10.2017 / 16:49

2 answers

1

According to the SQLite documentation the date (), time (), and datetime () functions can be written in terms of the strftime () function. So to do what you want, the query is as follows:

SELECT strftime('%Y-%m-%d',date_buy) as data, strftime('%H:%M:%S', date_buy) as hora FROM lancamento

On date you will have the format: yyyy-mm-dd and in the hour the format hh: mm: ss.

    
14.10.2017 / 19:56
1

% Y is for years% m is for months and% d is for Days   % H is for Hours% M is for minutes and% S is for seconds

SELECT strftime('%Y-%m-%d',date) as data,
       strftime('%H:%M:%S', date) as hora
FROM lancamento
    
10.11.2017 / 13:01