SOLR 3.1 - Date Issues - solr

We are using SOLR 3.1 and facing many problems with dates.
We are using database Sql Server 2005. So, when we imported data from database to collection, the first problem we faced is, 4 hours difference in the database and collection dates. For example, if database has date like 6/2/2011 10:00:00 PM it would be in the collection like this 2011-06-03T02:00:00Z. I am simply using database field to import. There is not date format or any other function involve in between.
How can we sort records by date? Right now, i am using it like this (*:*)&sort=resumeupdate+desc to fetch all the records and sort it by date. But it is not sorting properly.

Solr always stores its dates in UTC time. You need to both import your dates by transforming them to UTC and then convert your timestamps into UTC when you sort/filter. The dates Solr will return to you will be in UTC time, so you will need to convert them to the time zone you are in. Please see this issue for more details.
Otherwise, if everything is in UTC format then it should sort properly.

Related

How to save and search for EXACT date?

Setup
I'm creating a react app to save and retrieve daily reports from MongoDb Atlas database. There can be only one report per day per user. The search criteria for daily reports is the date of course.
Logic and code
The app has a calendar widget from material-ui datepicker. It returns the selected date with the current UTC time. But if I search the database using that directly, then obviously I won't find anything because of the difference of hours:minutes:seconds:milliseconds. It's impossible that the Date() that you're searching for would have the exact millisecond match with the time the report was created. So my idea was to store the date for each report with a time of exactly 12am i.e. 00:00:00:000Z as well as search the database with a date of time 12am.
selectedDate.setUTCHours(0,0,0,0); //sets the time to 12am
selectedDate.toISOString();
Question
Is this the right approach for this case? Will I face problems down the line doing it this way? How should the date be stored if it's the search criteria and if it has to be the exact match? Also it must serve any user around the world to save and retrieve their reports.
Thanks,
Suraj
You can store the date as you like, just in your db query use between condition
SELECT * FROM reports WHERE date BETWEEN '2020-05-01 00:00:00' AND '2020-05-01 23:59:59'

Logstash exception while fetching incremental data from SQL Server

I am using LogStash 7.3.2 to fetch incremental data from SQL Server using this query:
select * from mytable where lastupdatetimestamp > :sql_last_value
I also have specified last_run_metadata_path in logstash config file.
It works fine but sometimes it is throwing an exception:-
Exception when executing JDBC query {:exception=>#
transition (daylight savings time 'gap'): 1942-09-01T00:00:00.000 (Asia/Kolkata)>}
Why am I getting this exception and due to this exception it does not save last timestamp value and again it fetches duplicate records from SQL Server.
Any help regarding this would be highly appreciated.
As stated here
In Logstash if a datetime string has no TZ part it is assumed to be a UTC time.
If you know that the datetime is a local time string then you need to tell the date filter which timezone the date was generated in. You may use one of the Joda timezones,
e.g. America/New_York, America/Detroit or EST5EDT - these are merely labels that point to Timezone Java code that know what changes in clocks occurred in all timezones for quite some time into the past.
See this page for info on how the updates are followed. http://www.oracle.com/technetwork/java/javase/tzdata-versions-138805.html 100
Once the datetime string is converted to a Timestamp object (by the date filter) it is considered UTC time.

MS SQL to Excel - Timezones

I have
an SQL Server 2012, where datetime fields are stored in UTC time
an Excel File, that is integrated via ADO DB command objects to the SQL server
a function to check the current system settings, which allows to see the current system's difference to UTC
I need to display dates/times in Excel in local time (varies).
Until SQL Server 2016 (which we can't currently upgrade to), there is no Timezone support built-in to T-SQL.
There are various options that are playing around in my head, but I can't decide which one is worth pursuing:
- transmit the current time difference as a parameter to the Stored Procedure, and amend all date fields to apply that difference
- retrieve the UTC times, and return the field(s) as a formula (so instead of return field, field, created, modified I might return field, field, =fnUtcToLocal(#created#)... and so on
- retrieve UTC times, and use an adjacent formula (with QueryTable.FillAdjacentFormulas)
Regardless of the option, I've still got a problem left: When, for example, checking the system difference now in Excel when the user is in Eastern Standard Time, it is -5 hours. When my created date falls into the EDT time, the correction would still be -5 instead of -4 hours.
Does anyone have a smart idea on how I should approach this? Please let me know if any additonal detail is required.

Is there an equivalent to ConvertTimeFromUtc in MS SQL Server?

Is there a function in SQL Server that will convert a DateTime saved as UTC time to the local time? The problem is that I have times saved as UTC times, and I used to calculate time zone offset as
select #tzoffset = datediff(mi,SYSDATETIMEOFFSET(),SYSDATETIME())
and adding that to my UTC times, which worked fine until daylight saving came.
As that selects the current time zone offset, the calculation is invalid for pre-DST values.
As the dates are rendered in ASP.NET web form, I have worked around the issue by rendering the dates as TimeZoneInfo.ConvertTimeFromUtc((DateTime)Eval("maxtime"), TimeZoneInfo.Local), which works automagically.
Is there something similarly elegant in T-SQL?
It is not that simple. Read this http://blogs.msdn.com/b/bartd/archive/2009/03/31/the-death-of-datetime.aspx

DateTime.Today value changed when sending to the server

I am working with Silverlight and I am getting a problem. In my Database I have stored some dates with a format like this yyyy/mm/dd 00:00:00, which means that I store only the year, month and day, getting the time to 00:00:00.
When the client performs an action and sends to the server I get the DateTime.Today which will keep the format of my database date, but when it is sendind I get yyyy/mm/dd 22:00:00, so when my server side function gets the date, it will return no values from the database.
How can I fix this to get the correct datetime?
Thank you
Use UTC times to make sure you don't run into timezone issues.
You can see if the DateTime is UTC or local based by checking the Kind property, and you can get the current UTC time by DateTime.UtcNow.
DateTime structure is very prone to DST, timezones and cultures when serialising it.
are you serialising it at client side before push it ? what is the difference between client and server timezones ?
I would suggest that you try and consume DateTime.UtcNow and then serialise the data. i prefer to serialise using Invariant culture
HTH
In addition to storing UTC time in the database, you can hard set the time to 12:00:00 for all date values by using the Date property of the DateTime class.
DateTime.UtcNow.Date
You can present the date to the user in their local timezone using the ToLocalTime method:
DateTime.ToLocalTime().Date
I'm sure every database engine has a similar function, but the SQL Server function to get UTC date is (surprisingly enough):
GETUTCDATE()
I hope this helps.

Resources