EasyUI Forum
October 25, 2025, 04:27:20 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Entering date and time into datetime field  (Read 10297 times)
wel
Newbie
*
Posts: 30


View Profile Email
« on: January 13, 2016, 07:00:02 PM »

Hi,
I use MySQL "datetime" field to store date and time and I use inline grid editor and the column simply like this

Code:
 <th field="job_stamp" width="120" editor="datetimebox">Date and time</th>

The problem the drop down editor store date like that 1-14-2016 and database does not accept this format when I press save and then refresh I find the field become null again but if I enter the date manually like this 2016-14-1 I find it is stored normally !! how to fix this problem so user can use the drop down date and time combobox ?
« Last Edit: January 13, 2016, 07:03:15 PM by wel » Logged
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #1 on: January 13, 2016, 07:54:51 PM »

You have to set the format of the datetimebox editor.
Code:
<th field="job_stamp" width="120" data-options="
editor:{
type:'datetimebox',
options:{
formatter: function(date){
...
},
parser: function(s){
...
},
//...
}
}
">Date and time</th>

Please refer to:

http://www.jeasyui.com/forum/index.php?topic=3545.0
http://www.jeasyui.com/forum/index.php?topic=4011.0
Logged
wel
Newbie
*
Posts: 30


View Profile Email
« Reply #2 on: January 14, 2016, 10:31:19 AM »

Thanks jarry I used this code:

Code:
<th field="job_stamp" width="120" data-options="
                                    editor:{
                                        type:'datetimebox',
                                        options:{
                                            formatter: function(date){
                                                if (!(date instanceof Date)) date = new Date(date);
                                                var h = date.getHours();
                                                var M = date.getMinutes();
                                                var s = date.getSeconds();

                                                function _ff(v) {
                                                    return (v < 10 ? '0' : '') + v;
                                                };
                                                return _ff(date.getFullYear())+'-'+_ff(date.getMonth()+1)+'-'
                                                    +date.getDate() + ' ' + _ff(h)+':'+_ff(M)+':'+_ff(s);
                                            },
                                            parser: function(s){
                                                if ($.trim(s) == '') {
                                                    return new Date();
                                                }
                                                var dt = s.split(' ');
                                                var p1 = dt[0].split('-');
                                                var p2 = dt[1].split(':');
                                                return new Date(p1[0],p1[1]-1,p1[2],p2[0],p2[1],p2[2]);

                                            },
                                            required:true,

                                        }
                                    }
                                    ">Date and time
                                </th>
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!