In SQLite DB I m saving time as datetime('now') which as expected saving the time in YYYY-MM-DD HH:MM:SS.SSS format.
Now I want to retrieve time from that row in DD-MMM HH:MM format.
Is there any straight way of doing this?
Please Help.
Thanks.
Sample Code:
db.execSQL("INSERT INTO SessionInfo VALUES (00,'Demo Session',10,'Complete',7,datetime('now'),'"+usr_email+"');");
db.execSQL("INSERT INTO SessionInfo VALUES (01,'Demo Session',18,'Complete',8,datetime('now'),'"+usr_email+"');");
db.execSQL("INSERT INTO SessionInfo VALUES (02,'Demo Session',40,'Complete',4,datetime('now'),'"+usr_email+"');");
i want to retrieve data from any one row and the time should be in DD-MMM HH:MM format.
SQLite has the strftime() function, but there is no MMM format (whatever that may mean).
You should format dates in your application.
Related
I need to take a full timestamp column (Format: YYYY-MM-DD HH:MM:SS.SSSS) and convert it into hourly timestamp (Format: YYYY-MM-DD HH:00:00)
For example:
I want to convert my existing date:
2016-02-26 04:00:07.766304000
into:
2016-02-26 04:00:00
I tried to use unix_timestamp() and from_unixtime() function but it is too confusing :X
Does someone know how to easily do it?
Many Thanks for the helpers :)
You can use to_date() to get the date of the time and hour() to get the hour of the time, and then concat them together if you do not want to use unix_timestamp() or from_unixtime().
Suppose 'submit_time' looks like '2016-02-26 04:00:07.766304000'.
concat(to_date(submit_time),' ',cast(hour(submit_time) as string),':00:00')
will gives the answer.
As per seen in image my first query return 5 rows but my second query does not return any rows.
It shoud be return 3 rows.
I also have tried with
Store my all datetime data in format of 'yyyy-MM-dd hh:mm:ss'
"SELECT billheaderid,billheadercode,billtotalitem,billtotalamount,createdby,createdon WHERE cretedon >= Datetime('2014-08-19 12:26:32')"
Date values with "AM/PM" fields cannot be compared correctly with string comparisons
(1 is larger than 0).
You have to change all the values in the database to the correct format yyyy-MM-dd hh:mm:ss.
(And it is not necessary to call the datetime function.)
Store your data in form of
'yyyy-MM-dd hh:mm:ss'
And please care that '2014-08-19 03:45 PM' must be store as '2014-08-19 15:45:23' not as '2014-08-19 03:45:23'.
After that you don't need use datetime function. I am sure it'll work 100%.
What is the easiest way to strip milliseconds from a timestamp field. I am extracting data from a table and I want the data to be in YYYY-MM-DD hh:mi:ss format. but I am getting ss.ssssss in the data.
The following method should work:
SELECT CURRENT_TIMESTAMP
, CAST(CAST(CURRENT_TIMESTAMP AS CHAR(19)) AS TIMESTAMP(0));
I am having a column in my sql server database table with datatype bigint.
Now i need to convert this column into HH:MM:SS formate.
For this i use this command
SELECT cast(CONVERT(VARCHAR,DATEADD(MS,SUM(mFld),0),8) as Time) FROM tblm
But this command doesn't show right time duration.
For right time duration i use this command
SELECT rtrim(LTRIM(cast((mFld/(60*60)) as char)))+':' +rtrim(LTRIM(cast((mFld%(60*60))/(60)as char)))+':'+rtrim(LTRIM(cast(((mFld%(60*60))%(60)) as char))) FROM tblm
This command shows right result.But resulted data type is varchar.How can i convert this column in to time column with same result.
Example
DECLARE #minites bigint;
SET #minites = 5200020;
SELECT rtrim(LTRIM(cast((#minites/(60*60)) as char)))+':' +rtrim(LTRIM(cast((#minites%(60*60))/(60)as char)))+':'+rtrim(LTRIM(cast(((#minites%(60*60))%(60)) as char)))
SELECT cast(CONVERT(VARCHAR,DATEADD(MS,SUM(#minites),0),8) as Time)
How can i convert this column in to time column with same result.
You can't. Time has the range 00:00:00.0000000 to 23:59:59.9999999.
time (Transact-SQL)
I want to show a date in DD-MM-YYYY format in a datagrid. By default, SQLite stores the data in date-time format. So how can I convert date-time format to date format in flex by using SQLite?
You can use strftime, from Date And Time Functions.
Example:
SELECT strftime('%d-%m-%Y', 'now')
output:
10-06-2010
Look up Java until Date. It has methods to convert and is supported in SQLite. However it is mostly deprecated and replaced with Calender.