(date_time_selector)返回moodle

Does any one know if it is possible to have datetimepicker from date_time_selector function in moodle? I want the date/time selected from date_time_selector in a variable to store it into the database.

This is the code what I am working on right now in my edit.php , what am I missing

require_once('../../config.php');

require_once($CFG->dirroot.'/course/lib.php');

require_once($CFG->dirroot.'/blocks/myblcok/myblock_form.php');

global $DB;

require_login($SITE);

$block = new myblock();

$mform = new myblock_form();




if ($data  = $mform->get_data()) {


    $startdate = $data->startdate;
}




    $dataobject = new stdClass;
    $dataobject->name = get_string('entryname', 'myblock');
    $dataobject->description = get_string('entrydescription',
                                           'myblock');
    $dataobject->course = $COURSE->id;
    $dataobject->userid = $USER->id;
    $dataobject->starttime = $data->date;
    $DB->insert_record('event', $dataobject);
redirect($CFG->wwwroot.'/course/view.php?id='.$courseid, '', 0);

I'm presuming this is being used in a form? The return value from data_time_selector is a timestamp which can be stored in a database. eg:

In edit_form.php file

require_once($CFG->dirroot.'/lib/formslib.php');

class edit_form extends moodleform {

    function definition () {

        $mform =& $this->_form;

        $mform->addElement('date_time_selector', 'mytime', get_string('mytime', 'mycomponent'));

    }
}

In edit.php

require_once('edit_form.php');

$mform = new edit_form();

if ($data = $mform->get_data()) {
    // This is a timestamp.
    $mytime = $data->mytime;
}

EDIT:

Ah... you need to pass a data object to insert a record eg:

$newrecord = new StdClass();
$newrecord->mytime = $mytime;
$DB->insert_record('table', $newrecord);

Or if the form field names are the same as your field names, just use the $data object eg:

$DB->insert_record('table', $data);

Have a look through the database API :

http://docs.moodle.org/dev/Data_manipulation_API#Inserting_Records