Hacker News new | ask | show | jobs
by function_seven 1592 days ago
And the scales just fell from my eyes. I'm guilty of this in the system I develop at work. Whenever I want to show the user all widgets that were made on the date they selected, I will just do something like

    DATE(widget_made) = :user_date
Which does what I want and avoids the problem you brought up. But sometimes I have some more complicated logic that falls down if I try to compare datewise. So I manually create the DateTime ranges, and use 23:59:59 as the end of the range. So something like

    widget_made BETWEEN :user_date '00:00:00' AND :user_date '23:59:59'
Anything that came off the line at 23:59:59.3421 will be excluded. Fortunately for me, I don't think that has ever actually happened. But now I know to be on the lookout, and use proper date-handling tools to ensure correctness.