Comments on: Using Records to avoid problems with database date/time interval http://www.andreanolanusse.com/en/using-records-to-avoid-problems-with-database-datetime-interval/ Where Andreano Lanusse talk about technology, software development, programming techniques, databases, games and more through articles, tutorials and videos Wed, 02 Feb 2011 11:10:29 +0000 hourly 1 https://wordpress.org/?v=6.7.5 By: Andreano Lanusse http://www.andreanolanusse.com/en/using-records-to-avoid-problems-with-database-datetime-interval/#comment-2666 Fri, 16 Apr 2010 22:24:13 +0000 http://www.andreanolanusse.com/en/?p=294#comment-2666 In reply to Anthony Frazier.

Hi Anthony,

I agree StartOfTheDay() and EndOfTheDay() can use, but is not enough to fix the time problem. I update the code for 999, thanks.

]]>
By: Andreano Lanusse http://www.andreanolanusse.com/en/using-records-to-avoid-problems-with-database-datetime-interval/#comment-2665 Fri, 16 Apr 2010 22:19:51 +0000 http://www.andreanolanusse.com/en/?p=294#comment-2665 In reply to Istvan.

Hi Istvan and Louis, thanks for update, my mistake to set to 1000. I updated the post and source code to reflect that.

About the use of IncMillisecond and Trunc it works, but personally I don’t like that, the code became not intuitive and could generate some confusion, but this is my personal opinion.

]]>
By: Anthony Frazier http://www.andreanolanusse.com/en/using-records-to-avoid-problems-with-database-datetime-interval/#comment-2663 Fri, 16 Apr 2010 12:41:07 +0000 http://www.andreanolanusse.com/en/?p=294#comment-2663 For reports like that, I’ll pass my InitialDate & FinalDate parameters through StartOfTheDay() and EndOfTheDay() from DateUtils before fetching data.

With your TDateInterval class, wouldn’t you want SetFinalDate() to use 999 for the msec instead of 1000?

]]>
By: Louis Kleiman http://www.andreanolanusse.com/en/using-records-to-avoid-problems-with-database-datetime-interval/#comment-2661 Fri, 16 Apr 2010 11:07:42 +0000 http://www.andreanolanusse.com/en/?p=294#comment-2661 So, by design, you are missing values in the last second of the year? Dates are floating point. Trying to perform a query that gets everything up to midnight is easy: …where DateColumn >= Trunc(:StartDate) and DateColumn < Trunc(:EndDate) + 1. Plugging a StartDate of 1/1/2010 and an EndDate of 12/31/2010 into this query gives you everything that happened in that year without missing a record. Guaranteed. The Trunc and addition (+1) can be done in the front end or the back end. Your choice.

]]>
By: SimaWB http://www.andreanolanusse.com/en/using-records-to-avoid-problems-with-database-datetime-interval/#comment-2660 Fri, 16 Apr 2010 07:13:40 +0000 http://www.andreanolanusse.com/en/?p=294#comment-2660 Congratulations to Andreano. Great article….

]]>
By: LDS http://www.andreanolanusse.com/en/using-records-to-avoid-problems-with-database-datetime-interval/#comment-2658 Fri, 16 Apr 2010 07:05:45 +0000 http://www.andreanolanusse.com/en/?p=294#comment-2658 Don’t generate SQL predicates that way. Use parameters. For example Oracle won’t reuse statements from its cache, and you’ll get hard parse every time (unless you force it to reuse statements but that’s just a stopgap) and fill the cache.

When will Delphi have a timestamp type that can handle time zones as well?

]]>
By: Istvan http://www.andreanolanusse.com/en/using-records-to-avoid-problems-with-database-datetime-interval/#comment-2656 Fri, 16 Apr 2010 05:53:19 +0000 http://www.andreanolanusse.com/en/?p=294#comment-2656 Hi.
The above EncodeDateTime will raise an exception because 1000ms is not valid and should be set to 999. A better approach would be to just use IncMillisecond(Trunc(Value) + 1, -1); for Final date, and just simply Trunc(Value) for Start date.
I also don’t like the way you mixed in a fixed date format and the fixed SQL statement. Those are jobs of the presentation layer and the persistence layer. Besides that, I use records like that a lot 🙂

]]>
By: Cesar Romero http://www.andreanolanusse.com/en/using-records-to-avoid-problems-with-database-datetime-interval/#comment-2654 Fri, 16 Apr 2010 02:16:56 +0000 http://www.andreanolanusse.com/en/?p=294#comment-2654 Hi Andreano,

Great article, I really like the idea.

]]>
By: Colin http://www.andreanolanusse.com/en/using-records-to-avoid-problems-with-database-datetime-interval/#comment-2653 Fri, 16 Apr 2010 01:24:26 +0000 http://www.andreanolanusse.com/en/?p=294#comment-2653 Hi Andreano,

Excellent article! I had a similar problem but had to handle open-ended date ranges. I was going to tackle this by creating it as a class but making it as a record makes a lot more sense. Thank you for providing articles for not only on the “headlne” features but also for the small “trivial” features too 🙂

Colin

]]>