Search code examples
zend-frameworkzend-dbdatetime-format

store current date and time in the datetime format zend


I have a field called date_time in the database which is of type datetime. I have a form which on submit needs to enter the current date and time in the date_time field. How do I write my code so that the date_time field gets inserted with the current datetime. The following is my code: (I know I can't call NOW() like that, but I wanted to show what I want to achieve)

$qcData = Array(
    "date_time" => NOW(),
    "note" => $note                                         
);

$qcNotes = new App_Model_DbTable_QCNotes();
$qcNotes->insert($qcData);

Solution

  • here it is from the docs

    26.3.1. Current Date Without any arguments, constructing an instance returns an object in the default locale with the current, local date using PHP's time() function to obtain the UNIX timestamp for the object. Make sure your PHP environment has the correct default timezone.

    Example 26.2. Creating the Current Date

    $date = new Zend_Date();
    
    // Output of the current timestamp Feb 13, 2012 10:28:59 PM 
    print $date;
    //implement toString() output 2012-02-13 22:30:25
    print $date->toString('YYYY-MM-dd HH:mm:ss');