How to get tomorrow date as a string and date format in android for using in sqlite query?
up vote
0
down vote
favorite
I am trying to delete some records in s table where date is today's date and tomorrow's date
public void deleteAll()
// SQLiteDatabase db = this.getWritableDatabase();
// db.delete(TABLE_NAME,null,null);
SQLiteDatabase db = this.getWritableDatabase();
// db.execSQL("delete from "+ TABLE_NAME);
// db.execSQL("TRUNCATE table" + TABLE_NAME);
Date c = Calendar.getInstance().getTime(); System.out.println("Current time => " + c);
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String current_Date = df.format(c);
Log.e("Current_Date=", current_Date);
db.execSQL("DELETE FROM SchedledMeetings WHERE Meeting_Date = '''+current_Date+''' ");
db.close();
but would like to get these as a string and date format using a Sqlite query.
android android-sqlite
add a comment |
up vote
0
down vote
favorite
I am trying to delete some records in s table where date is today's date and tomorrow's date
public void deleteAll()
// SQLiteDatabase db = this.getWritableDatabase();
// db.delete(TABLE_NAME,null,null);
SQLiteDatabase db = this.getWritableDatabase();
// db.execSQL("delete from "+ TABLE_NAME);
// db.execSQL("TRUNCATE table" + TABLE_NAME);
Date c = Calendar.getInstance().getTime(); System.out.println("Current time => " + c);
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String current_Date = df.format(c);
Log.e("Current_Date=", current_Date);
db.execSQL("DELETE FROM SchedledMeetings WHERE Meeting_Date = '''+current_Date+''' ");
db.close();
but would like to get these as a string and date format using a Sqlite query.
android android-sqlite
all meetings are getting deleted
– harish Padmanabh
Nov 10 at 8:29
Please update your answer by editing it, instead of using comments.
– grooveplex
Nov 10 at 8:30
Also, your code can be SQL injected.
– grooveplex
Nov 10 at 8:33
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to delete some records in s table where date is today's date and tomorrow's date
public void deleteAll()
// SQLiteDatabase db = this.getWritableDatabase();
// db.delete(TABLE_NAME,null,null);
SQLiteDatabase db = this.getWritableDatabase();
// db.execSQL("delete from "+ TABLE_NAME);
// db.execSQL("TRUNCATE table" + TABLE_NAME);
Date c = Calendar.getInstance().getTime(); System.out.println("Current time => " + c);
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String current_Date = df.format(c);
Log.e("Current_Date=", current_Date);
db.execSQL("DELETE FROM SchedledMeetings WHERE Meeting_Date = '''+current_Date+''' ");
db.close();
but would like to get these as a string and date format using a Sqlite query.
android android-sqlite
I am trying to delete some records in s table where date is today's date and tomorrow's date
public void deleteAll()
// SQLiteDatabase db = this.getWritableDatabase();
// db.delete(TABLE_NAME,null,null);
SQLiteDatabase db = this.getWritableDatabase();
// db.execSQL("delete from "+ TABLE_NAME);
// db.execSQL("TRUNCATE table" + TABLE_NAME);
Date c = Calendar.getInstance().getTime(); System.out.println("Current time => " + c);
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String current_Date = df.format(c);
Log.e("Current_Date=", current_Date);
db.execSQL("DELETE FROM SchedledMeetings WHERE Meeting_Date = '''+current_Date+''' ");
db.close();
but would like to get these as a string and date format using a Sqlite query.
android android-sqlite
android android-sqlite
edited Nov 10 at 11:57
marc_s
564k12510881241
564k12510881241
asked Nov 10 at 8:25
harish Padmanabh
11
11
all meetings are getting deleted
– harish Padmanabh
Nov 10 at 8:29
Please update your answer by editing it, instead of using comments.
– grooveplex
Nov 10 at 8:30
Also, your code can be SQL injected.
– grooveplex
Nov 10 at 8:33
add a comment |
all meetings are getting deleted
– harish Padmanabh
Nov 10 at 8:29
Please update your answer by editing it, instead of using comments.
– grooveplex
Nov 10 at 8:30
Also, your code can be SQL injected.
– grooveplex
Nov 10 at 8:33
all meetings are getting deleted
– harish Padmanabh
Nov 10 at 8:29
all meetings are getting deleted
– harish Padmanabh
Nov 10 at 8:29
Please update your answer by editing it, instead of using comments.
– grooveplex
Nov 10 at 8:30
Please update your answer by editing it, instead of using comments.
– grooveplex
Nov 10 at 8:30
Also, your code can be SQL injected.
– grooveplex
Nov 10 at 8:33
Also, your code can be SQL injected.
– grooveplex
Nov 10 at 8:33
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
First I must say that it is wrong to store dates in SQLite
in format "dd/MM/yyyy"
because this is not a comparable format so it cannot be easily used to make selections when you want to get rows between dates. Also date functions of SQLite
would not recognize this format so you would have each time to convert it.
Better use this format: "yyyy-MM-dd"
.
Use this code:
Calendar calendar = Calendar.getInstance();
Date c = calendar.getTime();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String current_Date = df.format(c);
calendar.add(Calendar.DAY_OF_YEAR, 1);
c = calendar.getTime();
String tomorrow_Date = df.format(c);
db.execSQL("DELETE FROM SchedledMeetings WHERE (Meeting_Date='" + current_Date + "') OR (Meeting_Date='" + tomorrow_Date + "')");
db.close();
Notice that your DELETE
statement should look like this:
db.execSQL("DELETE FROM SchedledMeetings WHERE (Meeting_Date='" + current_Date + "') OR (Meeting_Date='" + tomorrow_Date + "')");
this way you pass the values of current_Date
and tomorrow_Date
and not the strings "current_Date"
and "tomorrow_Date"
.
This will delete all rows containing current date and tomorrow's date.
perfect. thanks alot
– harish Padmanabh
yesterday
@harishPadmanabh will you accept the answer?
– forpas
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
First I must say that it is wrong to store dates in SQLite
in format "dd/MM/yyyy"
because this is not a comparable format so it cannot be easily used to make selections when you want to get rows between dates. Also date functions of SQLite
would not recognize this format so you would have each time to convert it.
Better use this format: "yyyy-MM-dd"
.
Use this code:
Calendar calendar = Calendar.getInstance();
Date c = calendar.getTime();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String current_Date = df.format(c);
calendar.add(Calendar.DAY_OF_YEAR, 1);
c = calendar.getTime();
String tomorrow_Date = df.format(c);
db.execSQL("DELETE FROM SchedledMeetings WHERE (Meeting_Date='" + current_Date + "') OR (Meeting_Date='" + tomorrow_Date + "')");
db.close();
Notice that your DELETE
statement should look like this:
db.execSQL("DELETE FROM SchedledMeetings WHERE (Meeting_Date='" + current_Date + "') OR (Meeting_Date='" + tomorrow_Date + "')");
this way you pass the values of current_Date
and tomorrow_Date
and not the strings "current_Date"
and "tomorrow_Date"
.
This will delete all rows containing current date and tomorrow's date.
perfect. thanks alot
– harish Padmanabh
yesterday
@harishPadmanabh will you accept the answer?
– forpas
yesterday
add a comment |
up vote
0
down vote
First I must say that it is wrong to store dates in SQLite
in format "dd/MM/yyyy"
because this is not a comparable format so it cannot be easily used to make selections when you want to get rows between dates. Also date functions of SQLite
would not recognize this format so you would have each time to convert it.
Better use this format: "yyyy-MM-dd"
.
Use this code:
Calendar calendar = Calendar.getInstance();
Date c = calendar.getTime();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String current_Date = df.format(c);
calendar.add(Calendar.DAY_OF_YEAR, 1);
c = calendar.getTime();
String tomorrow_Date = df.format(c);
db.execSQL("DELETE FROM SchedledMeetings WHERE (Meeting_Date='" + current_Date + "') OR (Meeting_Date='" + tomorrow_Date + "')");
db.close();
Notice that your DELETE
statement should look like this:
db.execSQL("DELETE FROM SchedledMeetings WHERE (Meeting_Date='" + current_Date + "') OR (Meeting_Date='" + tomorrow_Date + "')");
this way you pass the values of current_Date
and tomorrow_Date
and not the strings "current_Date"
and "tomorrow_Date"
.
This will delete all rows containing current date and tomorrow's date.
perfect. thanks alot
– harish Padmanabh
yesterday
@harishPadmanabh will you accept the answer?
– forpas
yesterday
add a comment |
up vote
0
down vote
up vote
0
down vote
First I must say that it is wrong to store dates in SQLite
in format "dd/MM/yyyy"
because this is not a comparable format so it cannot be easily used to make selections when you want to get rows between dates. Also date functions of SQLite
would not recognize this format so you would have each time to convert it.
Better use this format: "yyyy-MM-dd"
.
Use this code:
Calendar calendar = Calendar.getInstance();
Date c = calendar.getTime();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String current_Date = df.format(c);
calendar.add(Calendar.DAY_OF_YEAR, 1);
c = calendar.getTime();
String tomorrow_Date = df.format(c);
db.execSQL("DELETE FROM SchedledMeetings WHERE (Meeting_Date='" + current_Date + "') OR (Meeting_Date='" + tomorrow_Date + "')");
db.close();
Notice that your DELETE
statement should look like this:
db.execSQL("DELETE FROM SchedledMeetings WHERE (Meeting_Date='" + current_Date + "') OR (Meeting_Date='" + tomorrow_Date + "')");
this way you pass the values of current_Date
and tomorrow_Date
and not the strings "current_Date"
and "tomorrow_Date"
.
This will delete all rows containing current date and tomorrow's date.
First I must say that it is wrong to store dates in SQLite
in format "dd/MM/yyyy"
because this is not a comparable format so it cannot be easily used to make selections when you want to get rows between dates. Also date functions of SQLite
would not recognize this format so you would have each time to convert it.
Better use this format: "yyyy-MM-dd"
.
Use this code:
Calendar calendar = Calendar.getInstance();
Date c = calendar.getTime();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String current_Date = df.format(c);
calendar.add(Calendar.DAY_OF_YEAR, 1);
c = calendar.getTime();
String tomorrow_Date = df.format(c);
db.execSQL("DELETE FROM SchedledMeetings WHERE (Meeting_Date='" + current_Date + "') OR (Meeting_Date='" + tomorrow_Date + "')");
db.close();
Notice that your DELETE
statement should look like this:
db.execSQL("DELETE FROM SchedledMeetings WHERE (Meeting_Date='" + current_Date + "') OR (Meeting_Date='" + tomorrow_Date + "')");
this way you pass the values of current_Date
and tomorrow_Date
and not the strings "current_Date"
and "tomorrow_Date"
.
This will delete all rows containing current date and tomorrow's date.
edited Nov 10 at 10:58
answered Nov 10 at 10:39
forpas
2,7481213
2,7481213
perfect. thanks alot
– harish Padmanabh
yesterday
@harishPadmanabh will you accept the answer?
– forpas
yesterday
add a comment |
perfect. thanks alot
– harish Padmanabh
yesterday
@harishPadmanabh will you accept the answer?
– forpas
yesterday
perfect. thanks alot
– harish Padmanabh
yesterday
perfect. thanks alot
– harish Padmanabh
yesterday
@harishPadmanabh will you accept the answer?
– forpas
yesterday
@harishPadmanabh will you accept the answer?
– forpas
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237255%2fhow-to-get-tomorrow-date-as-a-string-and-date-format-in-android-for-using-in-sql%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
all meetings are getting deleted
– harish Padmanabh
Nov 10 at 8:29
Please update your answer by editing it, instead of using comments.
– grooveplex
Nov 10 at 8:30
Also, your code can be SQL injected.
– grooveplex
Nov 10 at 8:33