Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time from database is always returned as nil

Status
Not open for further replies.

Kalisto

Programmer
Feb 18, 2003
997
0
0
GB
HI.
Ive got a simple MySql Table with a number of Time fields in it.

Ive also created a simple class (based on ActiveRecord) that relates to that table.

in console, if I look at an object of my class (i.e. foo = Class.first) I get the date/Times displayed, but not the Time fields. These all display nil)

I can get round this by converting my Times to DateTime and then ignoring the Date component, but thats just wrong.

So can anyone help me with what may be going wrong here?

Thanks

K
 
its of type time, some with a default value and some allowed to be null.

 
There is nothing in the class yet, Im working through some simple tutorials of stuff, so all I have is a database table with a few records in it. and then using script/console I typed in test = TimeSample.first

 
Okay, what about your migration?
Sounds like I'll have to build a test case on my side to see what's going on. Are you using Rails at all or just stuff based on ActiveRecord and the such? If so, what version?

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
Thanks for trying to help, Im at home now, so I'll pick this up again tomorrow!

But yes, its Ruby on Rails we are using, I'll confirm version number tomorrow as well :)
 
I'm looking at your original post again and it's not really making sense.

I tried something similar to what you did, and it works fine for me. If all you want to do is display the time part of datetime, then do something like this:
(this is taken from my show.html.erb)

<b>Test:</b>
<%=h @class_one.testme.to_s:)time) %>
</p>


My column 'testme' in mysql is "time", so it does not store a date.. And that means by default, Rails displays January 1st 2000. Doing .to_s:)time) tells it to disregard the time. Yes.. Rails is too smart for its own good sometimes ;-)

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
Not been able to get onto this today, so apologies for the lack of communication.

I'll fire up the dev box first thinkg tomorrow and post version numbers, table schema, and what Im doing, so hopefully you can spot the obvious mistake :)
 
Ok, not sure what Ive done apart from getting a clean installation and development machine, but the Time value works in my code now, so I'll put that down to an anomally, thanks for trying to help though
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top