The blog of Rahoul Baruah from 3hv Ltd

What's going on?

My name is Rahoul Baruah (aka Baz) and I'm a software developer in Leeds (England).

This is a log of things I've discovered while writing software in Ruby on Rails. In other words, geek stuff.

However, I've decided to put this blog on ice - I would ask you to check out my business blog here (or subscribe here).

17 April, 2006

The greatest thing DHH ever did

I was writing some SQL Server code to strip the time portion off a date/time value - it took me about half an hour to find a way of doing it that didn't kill performance (as I needed the calculation doing in the where clause of a select statement). The code I came up with was:

declare @DateAndTime datetime
declare @DateOnly datetime

select @DateAndTime = getdate()

select @DateOnly = cast(floor(cast(@DateAndTime as float)) as datetime)

select @DateAndTime as DateAndTime, @DateOnly as DateOnly

Half an hour for something that ought to be really simple. It made me think that date/time handling is pretty poor in nearly all languages.

Which is why the best thing that DHH ever did (if it wasn't him, my apologies to the author) was:


Not quite solving the problem described above but absolute genius and the way dates and times should work.


The next version of our application is going to have a denormalised date only field that is populated on a trigger. Ugly but better than the where clause hack shown above.


What's better than
10 minutes ago.

No comments:

eXTReMe Tracker