I have indexed a date in lucene using DateTools.dateToString to store the date in a particular field.
Is there any way to know if this was a date field, and more importantly how to get the date out again?
It's a fieldable with a long integer value.
Thanks
Lucene does not have strong-typing of fields, so the same field could have a date in one record and a string in another record, and a random integer in a third. It's up to your application to know what to look for in a particular field.
You can use the DateTools.StringToDate method to convert from a string back to a date.
Related
In my app, user will upload a document to the database under their subcollection, with a Timestamp attached to the document. In my Security Rules, I have it programmed so that the Timestamp will always be equal to FieldValue.serverTimestamp(). This saves a FieldValue to the database.
The problem is, whenever I get the documentSnapshot back from Firebase and access the field, it comes back as a Timestamp and not a FieldValue. Is there a way I can convert a Timestamp to a FieldValue, or vice-versa?
No, you really do want that Timestamp instead of a FieldValue. FieldValue tokens are only used for writing field values that need to have their actual values computed on the Firestore backend instead of on the client. They are just tokens, not actual values. When you fetch the document and read the value back out, it will have the actual Timestamp value (or whatever the final value is), which is what you need to work with.
I've been thinking it over, and I'm starting to wonder if this is even possible.
User Perspective:
There's a table of data, and one column contains a date. The user can type in a search term like dec and get all rows that occurred during December.
Backend: A jqGrid is used for displaying the table. It sends the entered search terms to the server. The server uses the code
Criteria cr = session.createCriteria( DetailedLogEntry.class );
Disjunction disjunction = Restrictions.disjunction();
MatchMode matchMode = MatchMode.ANYWHERE;
disjunction.add( Restrictions.ilike( searchKey.getField(), searchKey.getData(), matchMode ) );
cr.add( disjunction );
to apply the search terms, and where DetailedLogEntry contains a Date variable to represent the database's TIMESTAMPfield.
Because searchKey.getData() returns a string, comparing it against a date object results in an empty set.
So I guess the question is...is it possible, preferbly through Hibernate, to apply a restriction against a Date object as if it were a String?
That's not possible. You'd need to use Restrictions.between() and give it an upper and lower date values. You could use SimpleDateFormat to convert from your String values to Date values and then perform the search?
If the user searched for Dec, would you expect all the log entries from December of every year to show up? Can they type in :"1, Dec" and expect to see all the logs from the 1st December for every year? If it is string matching on dates you are looking for, it might be easier to load all the data into your jqGrid and use javascript to filter the table based on the string formatted date values.
Below is the snapshot of what I have got as a query from sqlite db.
After googling and reading a number of question around, I have come to know that to retrieve maximum datetime using aggregate functions like max() is not possible as sqlite doesn't support much datatypes but treats datatype as text.
So, I have brought this data in a List or at java level. So how could I now get the maximum datetime from this list.
Is there any direct construct for this format in java. Or do we have something at sqlite level that I coudn't find.
texts can be compared, sorted and ordered in SQLite.
Your format appears to be YYYY-MM-dd hh:mm:ss. Lucky for you, ordering this format result in ordering by date.
just
select current_test_id from someTable order by test_datetime desc limit 1
or
select current_test_id, max(test_datetime) from someTable
(or something, not entirely sure for the second one)
if you set the type of datetime field text then you can perform following query
but datetime must be yyyy-mm-dd hh:mm:ss
select max(datetime) from tableName;
A common approach is to store the data converted as long.
Use date.getTime() to get long from your Date instance and Date date = new Date(timestamp); to get a date object from your timestamp.
Once you have a long in your db you can perform any ordering / comparison you want.
To retrive max value from a set of Time of type (String) We have to do some concatenations using sub string .Using this Query max or min Time can be find out using sql lite
select max(datetime(case
when substr(TimeIn,7,2)='PM'
then substr(TimeIn,1,2)+12
else substr(TimeIn,1,2)
end || ':' || substr(TimeIn,4,2) || ':' || '00'))
from tablename
where Date='10/06/2016'
I was wondering how you can take just specific characters from a JTextField. For example if a JTextField has the date 20/12/2012 then how do you read only the "12" form the Field.
So is it possible and if so how or would it be easier to use multiple JTextFields?
One approach would be read full text, but split string based on "/" and take 0 index value in resulting array.
(or)
Parse String using SimpleDateFormatter and get Month from Date (assuming entered string will be always date)
If none of above works, then it would be easier to use multiple text fields
StringTokenizer can break up your string for you.
SimpleDateFormat can handle dates if you know the format in the field will be correct.
However having multiple fields for dates is common. You may just want different fields depending on your overall use of the data and user interaction with it.
I have a situation. I have two kinds of date in the mysql database. One is date and another is datetime. Now in hibernate criteria I have to check whether one date is greater than the other or not?
criteria.add(Restrictions.lt("award.deadline", "submission.date_received"));
But the different types are causing problems showing "java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date".
Even I tried to parse it using date parser but it is not taking as date as it is taking as string only. So, can you tell me how can we convert one date to different type inside the hibernate criteria?
The problem is, that Restrictions.lt(String propertyName, Object value) is the wrong Restriction. What you need is Restrictions.ltProperty(String propertyName, String otherPropertyName).
Explanation:
Restrictions.lt(String propertyName, Object value) is to compare a entity property with a specific Value
Restrictions.ltProperty(String propertyName, String otherPropertyName) is to compare a two entity properties
If you use Restrictions.lt("Y", "X") and "Y" is the name of a date property, then hibernate would try to translate "X" to an Date (not to an column name), and parsing "X" to an Date is, lets say, a bit complicated - so the Exception is rised.