View Full Version : Datefield format

31 Oct 2012, 11:50 PM
Hi all,

I am having a datefield control in my page.

xtype: 'datefield',
id: 'to-datefield',
maxValue: new Date(),
value: new Date(),
editable: false,
disabledDays: [0, 6],
format: 'd M Y', ///This is the format in which i want to show date in textbox (datefield)
submitFormat : 'Y m d' //this is the format in which it should return value

I want to show date in 01 Jan 2012 format which is working fine. But when I read the value of datefield. I want the value in 'Y m d' format. This is not working.

var toDate = Ext.getCmp('to-datefield').getValue();

So if user have selected 16 Oct 2012, using var toDate = Ext.getCmp('to-datefield').getValue(); returns me "Tue Oct 16 00:00:00 UTC+0800 2012" instead of returning "20121610". How can i make this control to return date in 'Y m d' format???

I want to store the date as 20121610 (Y m d format). I also want to know how can i assign this value (20121610) back to datefield control when i am loading the control.

1 Nov 2012, 12:43 AM
Probably it will format the date with submitFormat if you post it as a form.

I see in the docs a funtions that will return the pair key value that will probably return the desired frmat.

var keyPair = Ext.getCmp('to-datefield').getSubmitValue();

or else you can try to format it yourself

var val = Ext.Date.format( Ext.getCmp('to-datefield').getValue(), 'Y m d');


var val = Ext.Date.format( new Date(Ext.getCmp('to-datefield').getValue()), 'Y m d');