View Full Version : Problem with insert a date into database
janixams
20 Sep 2007, 8:51 PM
Hello:
I have a problem with insert a date into the database... I have a form with a datefield but, when I send the form data, the date inserted is wrong, that is, in the date field on datebase is the following: 0000-00-00.
Any idea about this.../????
Thanks in advance.
evant
20 Sep 2007, 8:57 PM
It could be a server side thing or a client side thing. Check the data being sent to the server using firebug, and check the value that is being passed to the DB.
catacaustic
20 Sep 2007, 10:10 PM
If I'm not wrong (and I usually am... :D), the Ext widgets store dates as a date Javascript date object, so when the values are sent back to the server, it's sent as a string formatted something like "Friday 21st September 2007, 12:55:25". That means that it won't be stored in a standard "0000-00-00" date column properly. What you need to do is set the format of the date before its sent back. It's not that hard, but if you can't find something let me know and I'll hunt through my code to see what I've done with it all.
janixams
21 Sep 2007, 7:31 AM
If I'm not wrong (and I usually am... :D), the Ext widgets store dates as a date Javascript date object, so when the values are sent back to the server, it's sent as a string formatted something like "Friday 21st September 2007, 12:55:25". That means that it won't be stored in a standard "0000-00-00" date column properly. What you need to do is set the format of the date before its sent back. It's not that hard, but if you can't find something let me know and I'll hunt through my code to see what I've done with it all.
Hi catacaustic,
Actually, I need your example code.
Thank you.
Animal
21 Sep 2007, 8:18 AM
What does the parameter look like when you get it back on the server?
janixams
21 Sep 2007, 10:46 AM
The problem is solved. When the values are sent back to the server, it's sent as a string formatted something like "Friday 21st September 2007, 12:55:25". Just like catacaustic say. Only I had to change the date format to "Y-m-d".
Now I use the following:
new Ext.form.DateField({
fieldLabel: 'Fecha de Origen',
name: 'fecha',
width:190,
allowBlank:false,
blankText:'Este campo es obligatorio.',
invalidText:'La fecha debe escribirse con el siguiente formato: aaaa-mm-dd',
format: 'Y-m-d'})
);That is all. The date is perfectly inserted in the database.
Thanks for your help.
catacaustic
21 Sep 2007, 5:21 PM
Great to hear. I'm glad I can be handy for something around here. :D
devil_mosh
13 Feb 2008, 11:22 AM
Great answer thanks dude!
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.