SQLite选择日期,具有不同的日期格式 [英] SQLite selecting date, with different date-format
本文介绍了SQLite选择日期,具有不同的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在按日期选择项目,但格式为YYYY-MM-DD HH:MM:SS。
我以为这会工作(从stackoverflow上的其他线程),但它不是:
I'm trying to select items by date, but their format is YYYY-MM-DD HH:MM:SS. I thought this would work (from other threads on stackoverflow), but it doesnt:
String selectQuery = "SELECT * FROM " + TABLE_LOG_WORKOUT + " WHERE strftime('%Y-%m-%d', " + KEY_DATE_BEGIN + ") = " + date;
- TABLE_LOG_WORKOUT为表格。
- KEY_DATE_BEGIN为YYYY-MM-DD HH:MM:SS-dates。
- 日期为YYYY-MM-DD试图查找结果。
推荐答案
date
是一个字符串文字,需要放在单引号。或者更好的是,使用?
占位符和绑定参数。
date
is a string literal and needs to be put in single quotes. Or better yet, use ?
placeholder and bind arguments.
没有语法错误,因为像$ code> 2014-11-27 是一个有效的表达式,计算结果为1976年。
There's no syntax error since something like 2014-11-27
is a valid expression that evaluates to the integer 1976.
这篇关于SQLite选择日期,具有不同的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文