I have a table with numbers:

15/10/2016 3/03/2016 4/05/2016 

I want to use the operator between , but I can't. I tried to use the strftime() function

 SELECT date, strftime('%Y', date) as year 

The result is NULL.

Full request:

 SELECT name, s_name, date, avg(price) FROM supp_order WHERE name = 'Ivan' and s_name = 'Ivanovich' and date_duties between '4/05/2016' and '15/10/2016' 

The problem with the date format, I do not know how to change.

  • show all request - Anatol
  • so why in a comment, add a question to the question - Anatol
  • add the same variant with between - Anatol Nov.
  • it is not clear what needs to be obtained and under what conditions - Anatol
  • I want to find the average number, I only have a problem with the date, I want to change the format - maxim Nov.

1 answer 1

SQLite does not have full support for Date-Time types, so you have to use one of the options below ...

SQLite does not have a storage class set aside for storing dates and / or times. The SQLite Functions of the Date and Time of Functions are not compatible with TEXT, REAL, or INTEGER values:

TEXT as ISO8601 strings ("YYYY-MM-DD HH: MM: SS.SSS").

Since it was noon in Greenwich on November 24, 4714 BC according to the pro leptic calendar Gregorian calendar.

INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC. It can be used for all applications.

Time strings

The following formats are available:

 YYYY-MM-DD YYYY-MM-DD HH:MM YYYY-MM-DD HH:MM:SS YYYY-MM-DD HH:MM:SS.SSS YYYY-MM-DDTHH:MM YYYY-MM-DDTHH:MM:SS YYYY-MM-DDTHH:MM:SS.SSS HH:MM HH:MM:SS HH:MM:SS.SSS now DDDDDDDDDD 

Example:

 sqlite> create table test(dt timestamp); sqlite> insert into test values('2016-11-29'); sqlite> insert into test values('2016-10-01'); sqlite> insert into test values('2016-12-01'); sqlite> .headers on sqlite> .mode column sqlite> select * from test; dt ---------- 2016-11-29 2016-10-01 2016-12-01 sqlite> select * from test where dt between '2016-11-01' and '2016-11-30'; dt ---------- 2016-11-29 
  • So it turns out that I need to change the data type in the column? - maxim Nov.
  • @maxim, yes, I gave an example in the answer - MaxU
  • And it is impossible to change this to our format on 11/29/2016 for example? - maxim Nov.
  • @maxim, you can, but then it will be a string and the comparison will not work ;-) - MaxU
  • Ok thanks for the answer. - maxim Nov.