Category Archives: javascript

Sqlite DateTime compare in WebSQL

Sqlite has DateTime. However, in my test ‘DateTime’ is similar with ‘Text’.

for example, javascript moment.js,

1
2
3
4
5
6
 
var date = new moment().format('YYYY-MM-DD hh:mm');
saveToDatebase(date);
 
var date = new moment().format('YYYY-MM-DD h:mm a');
saveToDatebase(date);

in sqlite, two different format will saved as different string.

it is better not to compare two different format, such as ’2016-10-10′ and ’2016-10-10 10:10:10′. it is comparable, but it is meanless.

therefore, in my test, and date time should be save as YYYY-MM-DD hh:mm, such as ’2016-10-10 10:10′ format.

then, sql statement like ‘select * from test where startDate < ’2016-10-10 15:15′ will work perfectly well.