How to order items from Room database by date with "MMM dd yyyy" format - android-room

I'm trying to order items by date from Room database, where the dates are stored as strings with this format MMM dd yyyy. Is there any way I could do this without changing structure of my database?
I tried #Query("SELECT * FROM table ORDER BY date") which just orders the months alphabetically.

I fixed my issue by changing my date format to from Jan 01 2019 to this format 2019 01, 01 and when retrieving from database, I order by the new date format.
NOTE: This might not be the best solution but it worked perfectly for what I'm trying to achieve.

Related

How to Convert ddmmyyyy to year(Date)?

I am new to OBIEE
I have date in ddmmyyyy format .
How can i create Year, Quarter, Month as separate fields out of that?
Example:
Order_date
21/11/2017
02/09/2016
OutPut
Year
2017
2016
Month
11
09
In OBIEE a time value (i.e. now()) evaluates to quarter of year as:
qarter_of_year(now())
to year as:
year(now())
to month as
month(now())
+1 to Christian - just use the actual OBI functions!
If it doesn't work you are probably not working with actual DATE data types but some numerical or varchar types.

DataTable DateTime difference between oracle database

I'm getting date from oracle to datatable, but the date is not correct. But if I get date to simple string, the date is correct.
The real data in the Oracle: 2015-01-01 09:00:00 (real)
In the datatable the same date is: 2015-01-01 16:00:00
If I get this date to simple string, I get this: 2015-01-01 09:00:00 (real)
The Oracle server is in the USA, the IIS Webservice is in Ireland, and the application is running in different countries.
I tried change the column DateTimeMode, but it is not possible if there are data. I did not want to change individually..
But I cant create columns before the query, because I need dynamic columns.
Could you help me please?

Oracle Insert from TH Date Format

I have the Data in the date formats of
2nd November 2010
15th Mar 2013 -- and so on.
I need to pick up these data and insert into the field of type DATE.
How can I achieve that?
select to_char(sysdate,'ddth Month YYYY','NLS_DATE_language=American') from dual
output:
19th November 2014
select to_date('15th Mar 2013','dd"th" Mon YYYY','NLS_DATE_language=American') from dual
used to trans varchar to date format.
Hope helps you.
You just need to cast the string to a date with the appropriate format mask:
insert into your_table values (
to_date('2nd November 2010', 'ddth Month YYYY')
)
The documentation has a complete list of format models. Find out more.
However, you have a problem because your input has different formats. We cannot use the same mask to match NOVEMBER and MAR; the second date requires a mask of 'ddth Mar YYYY'.
So you will need to write a function which catches ORA-01861: literal does not match format string and applies a different mask; depending on the quality of your input data you may need to have several of these. This situation is common with applications which don't use strong data-typing, and so demand data cleansing when they interact with more rigourous systems.

Convert time stored as hh24miss to hh24:mi:ss

I have a column in my table which will store the time as hh24miss format, i.e it stores as 091315 which is 09 hrs 13 min 15 sec. I need to convert it into HH24:MI:SS AND concatenate it with the date column which is in YYYYMMDD format.
Simply, the following columns Date: 19940601 and Time: 091315 need to be converted to
01-Jan-94 09:13:15.
You should not store dates as strings, and there is no need to store the time in a separate field. Oracle's DATE data type includes times down the to the second. (You'd need TIMESTAMP for fractions of a second).
If you are really stuck with this schema then you need to convert the two strings into a DATE:
to_date(date_column || time_column, 'YYYYMMDDHH24MISS')
You can then display that in whatever format you want; what you showed would be:
to_char(to_date(date_column || time_column, 'YYYYMMDDHH24MISS'),
'DD-Mon-RR HH24:MI:SS')
Although the data you have is June, not January.
SQL Fiddle demo.
But really, please revisit your schema and use the appropriate data type for this, don't store the values as strings. You have no validation and no easy way to check that the values you have stored actually represent valid dates and times.

Date returned with Jdbc is in PDT timezone

I have written a stand-alone script that stores dates (Date type field) in a mySQL database using Google Apps Script JDBC object. The timezone of the dates is UTC.
I do a query that selects all the dates, as an example:
SELECT Date1 FROM Table1
When I retrieve the data using GetObject(1), it returns a Date object having PDT timezone set.
To be more precise, when I prompt theDate.toString(), it gives me:
Mon Jul 30 2012 23:51:25 GMT+0200 (CEST)
I notice that the original date (2012-07-30 14:51:25) from db has been considered as PDT and converted to GMT+2.
The Script timezone is not related and is set to GMT+1...
How can I tell to JDBC that the dates from the database are UTC?
Thanks
Some debugging done in Issue 1642 indicates that this is due to how JDBC works with MySQL, and the connection flags required to fix it currently can't be set in Apps Script.
To be clear through, the timezone shown when converting a JavaScript Date to a string will always be the timezone of the server, in this case Pacific Time. Use Utilities.formatDate to display a Date in a specific timezone.

Resources