If txtregisterdatetime is a string/varchar field, then setting it to
Time.now.strftime("%d-%m-%Y %I:%M%p") and saving it should store the
formatted version. But if it’s a time/date field, it’s always going to
get stored in the database’s internal format, and reformatting it before
saving won’t acccomplish anything.
Generally, you should store times and dates as the apporpriate time/date
datatype in the database, and not as text strings. You reformat whenever
you want to use it, into an instance variable like, say
@formatted_time = @myobject.datefield.strftime("%d-%m-%Y %I:%M%p")
and then display @formatted_time in your view.
I’m still not able to get this to work! The date and time are still
coming up like this “Tue Apr 04 00:00:00 GMT Daylight Time 2006”. The
following is what I have put in my controller:
@tblregisteredphone.txtregisterdatetime = Time.now("%d-%m-%Y %I:%M%p")
redirect_to :action => ‘list’
Can anyone tell me where I’m going wrong?
Thank you for your replies,