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.










share|improve this question























  • 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














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.










share|improve this question























  • 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












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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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












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.






share|improve this answer






















  • perfect. thanks alot
    – harish Padmanabh
    yesterday










  • @harishPadmanabh will you accept the answer?
    – forpas
    yesterday










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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.






share|improve this answer






















  • perfect. thanks alot
    – harish Padmanabh
    yesterday










  • @harishPadmanabh will you accept the answer?
    – forpas
    yesterday














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.






share|improve this answer






















  • perfect. thanks alot
    – harish Padmanabh
    yesterday










  • @harishPadmanabh will you accept the answer?
    – forpas
    yesterday












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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














































































Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

Evgeni Malkin