1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    14
    Vote Rating
    0
    TouchOfDestiny is on a distinguished road

      0  

    Default ExtJS Date Format -> Datetime field in MySQL Table

    ExtJS Date Format -> Datetime field in MySQL Table


    Hi!

    I have a model with a date field:

    fields: [
    ...
    {name: 'startDate', type: 'date', dateFormat: '?any idea?'},
    ...
    ]

    and a form with a datefield:
    ...{
    xtype: 'datefield',
    name: 'startDate',
    format: 'd.m.Y',
    fieldLabel: 'Starttag'
    }..

    Now, what I would like to do is to "send" the value of this field to the server (MySQL), in a table with a datetime field. The problem is, that I can't succeed in doing it, 'cause the field in my DB is always null.

    I have to use a datetime field in my DB, so I wonder if there's a way to send the date that is set in the form + a time like 00:00:00.

    In the form:

    02.03.2012

    To the server:

    03/02/2012 00:00:00 (or something like that)

    Thank you very much in advance for any advice.

    David

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,992
    Vote Rating
    456
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    You can use the following:

    model::fields
    Code:
    { name: 'date_updated', type: 'date', dateFormat: 'Y-m-d' },
    column:
    Code:
    function render_date(val) {
        val = Ext.util.Format.date(val, 'm/d/Y');
        return val;
    }
    { dataIndex: 'date_updated', header: 'Requested', renderer: render_date }
    backend(php)
    Code:
        function fix_date($date)
        {
            // change field to null, null must be allow in table for date field
            // change blank to null or todays date will be created as default
            if (strchr($date, '1899') != FALSE || empty($date)) {
                return NULL;
            } else {
                $dateTime = new DateTime($date);
                return date_format($dateTime, 'Y-m-d');
            }
        }
    Regards,
    Scott.

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    14
    Vote Rating
    0
    TouchOfDestiny is on a distinguished road

      0  

    Default


    Thanks for you're reply, Scott!

    There's no grid in my application, so I can't use a render function. Just a dialog (a window) with a form with many fields. The datefield (which shows that beautiful calender when you click on it) must display the date in the format "d.m.Y". Is there a way to display in the form the date in this format and to send it to the server in another format compatible with mysql?

    When I "submit" my form and send the data to the server, the datetime field in the mysql table is always null.

    David

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,992
    Vote Rating
    456
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    That is fine .. the dateFormat in your field define will send it in that format (y-m-d), while your format in your datefield will still display in d.m.y

    Scott.

Thread Participants: 1

Tags for this Thread