Populate Date Field in MySQL Database

Hello all, I have a brief question…

I have a MySql database that includes a field of type “Date”. I have a javascript method that will create a new record in this tabe and attempt to enter todays current date in the field. Yet every time I try to run it I get an error…
“Setting dataprovider with name “creation”/type ‘DATETIME’ with value of wrong type ‘2004-05-12’”

I have tried several different ways to forumlate the entry with no success. Am I just formating the entry wrong? The odd part is that I can just type the exact same string (2004-05-12) into the field manually with no problem.

I have tried just about every format I can think of and tried different properties of the Date object to enter.

Sample Script…

//New Date Object
today = new Date();
account_to_staffcomment.newRecord();
account_to_staffcomment.account_idaccount = idaccount
//Creation is a field of type “Date”
account_to_staffcomment.creation = today.toDateString();

Thanks for any help you can provide! I promise one day I’ll be smarter and answer more questions then I post!

Jim

try this(setting column with a date object instead of a string)

account_to_staffcomment.creation = new Date(); 

there’s also a column autoenter property in servoy where you can set creationdate/ modifieddate etc..

account_to_staffcomment.newRecord(); 
account_to_staffcomment.account_idaccount = idaccount

When you create a new record through a relation
the foreign key is set automatically.
(I’m assuming "account_to_staffcomment.account_idaccount " is your foreign key?)

Also, don’t use the “date” type for this in mysql. Try either “datetime” or “timestamp.”

Date reference

  • David

Thanks for the suggestion with the Date object. It worked like a charm!

I am curious though. After reading about the difference between a Date and DateTime and Timestamp fields I am pretty sure that I want to use the Date field. (I am really only interested in the date the record is created.) But after David’s suggestion, I can help but wonder why I should consider Datetime or timestamp?

Is there somthing wrong with the Date field type?
Can I search though it and find record before such and such date?

Jim