Populate Date Field in MySQL Database

Questions and answers regarding general SQL and backend databases

Populate Date Field in MySQL Database

Postby gte451f » Thu May 06, 2004 11:37 pm

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
gte451f
 
Posts: 45
Joined: Mon Jan 19, 2004 12:53 am

Postby maarten » Fri May 07, 2004 9:06 am

try this(setting column with a date object instead of a string)
Code: Select all
account_to_staffcomment.creation = new Date();

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


Code: Select all
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?)
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby david » Fri May 07, 2004 5:22 pm

Also, don't use the "date" type for this in mysql. Try either "datetime" or "timestamp."

Date reference

- David
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

It works!

Postby gte451f » Tue May 11, 2004 2:19 am

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
gte451f
 
Posts: 45
Joined: Mon Jan 19, 2004 12:53 am


Return to SQL Databases

Who is online

Users browsing this forum: No registered users and 35 guests

cron