PDA

View Full Version : Converting DateField format to SQL YYYY-MM-DD



Bigtime
10 Jun 2010, 6:52 AM
Hi All,

I have run into a bit of an issue. I am using the DateField in the following manner in a grid,


header:'Startdate',
dataIndex: 'startdate',
width: 100,
sortable: true,
editor: new Ext.form.DateField({
format: 'm/d/y',
minValue: '01/01/06',

I have an afterEdit function defined in the following way:




otfgrid.on('afteredit', afterEditotf);
function afterEditotf(e) {
var r = e.record;
var col = e.field;
var id = r.get('ID');
var mode = 'edit-contract-items';

Ext.Ajax.request({
url:'/admin/billing/ajx/saveupdate.php',
params:{ID:id,col:col,value:e.value,mode:mode},
success: function () {
onetime_fee_ds.reload();
recurring_fee_ds.reload();
}

});
}

e.value is the column field value. My problem is that the js date format output is something like the following:

Mon May 31 2010 00:00:00 GMT-0400 (Eastern Daylight Time)

And my sql statement that is simply,


$sql = "UPDATE fees SET ".$col." = '".$value."' where ID = ".$id;

Works great, unless I have to transform the data, as the date may need to be. Is there a simpler way to do this?
Preferably directly from the Datefield.

Thanks,
BT

mslimmer
10 Jun 2010, 11:13 AM
you can determine if the event is for a date field (by e.field == 'datefieldname' or digging deeper) then
var val;
if (field == 'mydatefield') { val = e.value.Format('Y-m-d'); }
else {val = e.value;}

or something like that see API documentation for date

max

Bigtime
10 Jun 2010, 11:56 AM
Thanks Max, I looked at the API doc for Format and it wasn't super clear to me..Following your suggestion I am getting the following error in firebug.

e.value.Format is not a function

if (e.field == 'startdate') { val = ...t('Y-m-d')); } else {val = e.value;}

Thanks again!

mslimmer
10 Jun 2010, 12:00 PM
try lowercase format() (it's upper if you call Ext.util.Format.date(rec.get('workdate'), 'l')
you can set a break point in firebug and play with it, look for functions...

max