Thursday, June 25, 2009

insert date in sqlserver

Recently I saw a strange behavior, and I don't know why. When I create a new object model and set its attributes, if I set the date, then in the DB it shows me the day before.

For example:

abc = ABC.find(:first, :conditions => "id = 1")
puts abc["date"] # 2009-06-25

#let's create a new object 'model' and set the same date as ABC
model = = abc["date"] = "a name"!

After, in Sqlserver management studio:

select * from model;

--date = 2009-06-24 15:00:00:000
--name = "a name"

So why it's not the 25th?? Is there a bad configuration somewhere? Well, I don't know. When I have more time, I'll try to understand why, but for now, to avoid this problem, I'm doing the following: = "#{abc["date"] }"

No comments: