Usage of Time.now or Time.now.to_s or Time.now.to_datetime is throwing error.
Usage of Date.today doesn't help as it stores the date with time as 12.00 AM and not the current time stamp.
Please help me in resolving this issue.
Usage of Time.now or Time.now.to_s or Time.now.to_datetime is throwing error.
Usage of Date.today doesn't help as it stores the date with time as 12.00 AM and not the current time stamp.
Please help me in resolving this issue.
Did you try a statement of the kind (with now() in the update statement):
INSERT INTO table1 (field1, field2, field3, timestampfield) VALUES ('value1', 'value2', 'value3', now())
[EDIT:] Have a look here for an explanation of "now()"
For update try something like:
UPDATE table1 SET mytime = now();
Another option for you if you want to put proper time on insert, it is just set function now() for the datetime field default.
I'm not sure why and what is throwing an error, but if you're trying to generate a date string that is correct SQL from Ruby (specifically Rails here) you can use Time.now.to_s(:db)
.
Time.now.to_formatted_s :db this should give you db friendly time stamp.
http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Conversions.html#M001093