我想将今天的日期与SqfLite数据库中存储的日期进行比较,如果日期匹配,请执行一些操作。
我的桌子:
Vara.fromJson(Map<String, dynamic> json){
this.id = json[DatabaseCreator.id]; // int primary key
this.varuNamn = json[DatabaseCreator.varuNamn]; //text
this.utgangsDatum = json[DatabaseCreator.utgangsDatum]; //text
}
到目前为止,我的代码:
Future getVaraDate() async {
DateTime now = new DateTime.now();
var date = now.toString().substring(0,10);
final sql = '''Select * from ${DatabaseCreator.varuTable} where ${DatabaseCreator.utgangsDatum} == "$date" ''';
List<Map> result = await db.rawQuery(sql);
// What to do here?
}
输出:
I/flutter ( 8118): [{id: 36000291452, varuNamn: hej, utgangsDatum: 2019-05-19, isDeleted: 0}]
我被困住了,任何帮助将不胜感激!
答案 0 :(得分:0)
所以解决了以下问题:
Future getVaraByDate() async {
DateTime now = new DateTime.now();
var date = now.toString().substring(0,10);
final sql = '''Select * from ${DatabaseCreator.varuTable} where ${DatabaseCreator.utgangsDatum} == "$date" ''';
List<Map> result = await db.rawQuery(sql);
if(result.isNotEmpty){
var firstResult = result[0];
var dateResult = firstResult.values.elementAt(2);
return dateResult;
print(dateResult);
} else {
print("No matches");
}
}