Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strftime function in SQLite does not work

Hi, I am using the following query but it does not work,

SELECT strftime('%m',Since) AS Month FROM Dates

Type of Since column is DATETIME, but the result is shown an empty Month column without any error.

like image 489
Eme Emertana Avatar asked Jul 03 '26 11:07

Eme Emertana


1 Answers

strftime isn't broken, it just doesn't understand the format of the datestamps in your database.

SQLite version 3.7.9 2011-11-01 00:52:41
sqlite> create table dates (id int, d datetime);
sqlite> insert into dates (id,d) values (1, date('now'));
sqlite> insert into dates (id,d) values (2, 'bad date');
sqlite> insert into dates (id,d) values (3, NULL);
sqlite> insert into dates (id,d) values (4, datetime('now'));
sqlite> select * from dates;
1|2012-09-23
2|bad date
3|
4|2012-09-23 04:31:36
sqlite> select id, strftime('%m', d) from dates;
1|09
2|
3|
4|09
like image 134
j.w.r Avatar answered Jul 06 '26 07:07

j.w.r



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!