SQLite: Current date plus one day in where clause
I need to get 3 queries on an 'appointment' table.
- where appointment.start_date is today,
- where appointment.start_date = today+1 day, and
- where appointment.start_date is > today+1 day.
I've got 1. down fine.
var resultSet = conn.execute('SELECT * FROM appointments WHERE date() = date(start_date)');
For 2., I've tried this:
var resultSet = conn.execute('SELECT * FROM appointments WHERE date("now", "+1day") = date(start_date, "+1day")');
I got date('now', '+1day') fr开发者_开发百科om this link this link but it returns the same results as the first query.
Can someone help with these queries?
If you're using exactly what's posted, I'd say you have a spacing problem
SQLite uses '+1 day' and you have posted '+1day'
Barring any explicit error messages, with the space it should work
I'm not sure for SQLite, but try next code:
var now = new Date();
var nowStr = now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
var nowPlus1 = new Date(Number(now)+24*60*60*1000);
var nowPlus1Str = nowPlus1.getFullYear()+"-"+(nowPlus1.getMonth()+1)+"-"+nowPlus1.getDate();
var resultSet = conn.execute("SELECT * FROM appointments WHERE start_date = '" + nowStr + "'");
var resultSet = conn.execute("SELECT * FROM appointments WHERE start_date = '" + nowPlus1Str + "'");
var resultSet = conn.execute("SELECT * FROM appointments WHERE start_date > '" + nowPlus1Str + "'");
Sorry totally my own idiosity my query was wrong: WHERE date("now", "+1day") = date(start_date, "+1day") should have read WHERE date("now", "+1day") = date(start_date) I had an extra +1 day. Doh!
Try with "plus one day" instead of "+1 day". Its not documented, but worked for me in another code.
var resultSet = conn.execute('SELECT * FROM appointments WHERE date("now plus one day") = date(start_date plus one day")');
精彩评论