PDA

View Full Version : Unix Timestamp in DatePickerField



BenMajor
18 Mar 2011, 6:21 AM
Hi,

I have the following code which is used to generate a Birthday field in a profile Panel in my app:


var profileForm = new Ext.form.FormPanel({
title: 'Profile',
standardSubmit : false,
items: [{
xtype: 'fieldset',
title: '',
instructions: 'Edit your profile above',
defaults: { labelAlign: 'left', labelWidth: '40%' },
items: [
{ xtype: 'datepickerfield', name: 'dob', label: 'DoB', value: user.dob }
]
}]
});

user.dob is a Unix Timestamp formatted date string, and I want to know how I can set the default value of the DatePickerField to recognize and correctly format the timestamp. I've tried
dateFormat: 'time' without success. Any help would be gratefully received.

Thanks,
Ben.

mitchellsimoens
18 Mar 2011, 8:03 AM
tried


dateFormat: "U"

?

BenMajor
18 Mar 2011, 8:26 AM
Thanks for your reply, Mitchell.

I just tried adding dateFormat: 'U' without much success. Here's the code I'm using:


{ xtype: 'datepickerfield', name: 'dob', label: 'DoB', value: user.dob, dateFormat: 'U' }
// For reference, user.dob = 1300456519

Regards,
Ben.

mitchellsimoens
18 Mar 2011, 8:34 AM
Try this:


{
xtype : 'datepickerfield',
name : 'dob',
label : 'DoB',
value : Date.parseDate(user.dob, "U")
}

BenMajor
18 Mar 2011, 11:10 AM
Thanks, but that only brings up today's date, unfortunately. :s

mitchellsimoens
18 Mar 2011, 11:13 AM
The timestamp of 1300456519 equals 3/18/2011 13:55:19 GMT

BenMajor
18 Mar 2011, 11:18 AM
Oh boy do I feel silly now. Turns out there's an error in the PHP which is not saving the correct timestamp back to the database...

Sorry! :">

mitchellsimoens
18 Mar 2011, 11:20 AM
Oh boy do I feel silly now. Turns out there's an error in the PHP which is not saving the correct timestamp back to the database...

Sorry! :">

Stupid mistakes are all apart of the job :D