简体   繁体   中英

Need sqlite Query with substring

I want to fetch records from sqlite database table called messages. I have a column named like Message_dated in the form of following "Jan 20, 2015 10:31:23". But in the cursor it is giving as it is.But now i want only date from message_dated column i dont want time.I am using to call query like following.But it is giving full date and time.

ColumnName = DatabaseHelper.TABLE_MSGS.COL_MESSAGE_DATED,
ColumnId =  DatabaseHelper.TABLE_MSGS.COL_MESSAGE_DATED
String[] columns = new String[] {
                DatabaseHelper.TABLE_MSGS.COL_MESSAGE_ID + " as _id",
                columnName, columnID };
cursor = db.query(DatabaseHelper.TABLE_MESSAGES_NAME,
                    columns, null, null, columnID, null, null);

Please tell me how can i do it.Thanks in advance.

you can't retrieve it without time because a date object is already found to return that, however you can manipulate it so you can store it in a string and use it in a different format using the code bellow:

String input = "Jan 20, 2015 10:31:23";
DateFormat inputFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
Date date = inputFormatter.parse(input);
DateFormat outputFormatter = new SimpleDateFormat("MM/dd/yyyy");
String output = outputFormatter.format(date); 

hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM