When using dates in Rails with SQL server everything seems to work great until I attempt to use a date prior to 1970. I can see the date is correct in the database but when I attempt to read the value it is returned as nil, if I ask for it again I get the correct date. I can write dates prior to 1970 into the database however I think is facilitated by validates_date plugin which seems to work a charm. Without the plugin I think I would get errors. If in my controller I ask for the date to be formated as string and just rescue the failure as it always fails first time, then the date works from then on, but I would really like to get this fixed so I dont have to perform this little dance every time I use a date field. I have found a bug report http://dev.rubyonrails.org/ticket/3430 which was opened around 2 years ago and there are a couple of suggestions but none seem to work for me. Does anyone have any suggestions? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
forgot to add that its rails 1.2.3 Here is the console feedback showing the issue as well.>> can = Candidate.find(1)can = Candidate.find(1) => #<Candidate:0x4658160 @attributes={"canid"=>"", "minority_id"=>nil, "adjustment_assessment"=>"", "adjustment_learning"=>"", "sensory_id"=>nil, "gender"=>"Male", "firstname"=>"B ", "lastname"=>"Jones", "id"=>1, "assessment_id"=>1, "note_take_method_id"=>nil, "help_achieve"=>"", "additional_evidence"=>"", "date_of_birth"=>"1901/04/04 00:00:00"}>>> can.date_of_birthcan.date_of_birth => nil>> can.date_of_birthcan.date_of_birth => #<DateTime: 4830957/2,0,2299161>>>Its just plain weird. On Jul 26, 4:33 pm, MagpieUK <irvin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> When using dates in Rails with SQL server everything seems to work > great until I attempt to use a date prior to 1970. I can see the date > is correct in the database but when I attempt to read the value it is > returned as nil, if I ask for it again I get the correct date. > > I can write dates prior to 1970 into the database however I think is > facilitated by validates_date plugin which seems to work a charm. > Without the plugin I think I would get errors. > > If in my controller I ask for the date to be formated as string and > just rescue the failure as it always fails first time, then the date > works from then on, but I would really like to get this fixed so I > dont have to perform this little dance every time I use a date field. > > I have found a bug reporthttp://dev.rubyonrails.org/ticket/3430which > was opened around 2 years ago and there are a couple of suggestions > but none seem to work for me. > > Does anyone have any suggestions?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I know I keep talking to myself but here goes nothing. In the model I have added: def date_of_birth Date.parse(self.date_of_birth_before_type_cast) end Which means that the date returns first time, so the problem is definately to do with the casting of the field. How I fix this I don''t know yet, but at least the workaround seems to do the trick. And I only need to add it to each model using dates but better than in the controllers. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---