Topic: SQL Date is for Date.today as SQL Datetime is for ...

Hi there,

I have a table of versions (id, version, realease_date).

Originally, the release_date field was a Date on my database but I've changed it to Datetime.

To automatically create a Date (so the user wouldn't have to when creating a new version) I added:

def create
  ...
  @version.release_date = Date.today
  if @version.save
  ...
end

What is the equivalent of the above now that I'm dealing with Datetime?

I've tried @version.release_date = DateTime.now but that gave me the following error:
Mysql::Error: #22007Incorrect datetime value: '2006-11-23T16:15:13Z' for column 'release_date' at row 1:

(Which I can plainly see is wrong, because of the T and Z that appeared...)

Thank you for your help,

Fabricio.

Re: SQL Date is for Date.today as SQL Datetime is for ...

@version.release_date = Time.now

should work.

Re: SQL Date is for Date.today as SQL Datetime is for ...

did you try DateTime.now.to_date ?

Re: SQL Date is for Date.today as SQL Datetime is for ...

@version.release_date = Time.now gave me a SQL Datetime perfectly, thank you very much!


Unfortunately @version.release_date = DateTime.now.to_date gave me the exact same problem as my original posting @version.release_date = Date.today that is:

Mysql::Error: #22007Incorrect datetime value: '2006-11-24T09:11:49Z' for column 'release_date' at row 1: ...

Fabricio