• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
inserting date problem


I can't seem to properly insert date to the database without getting a 00-00-00 result in the database

here is my model
function insertginfo($sessionid='', $firstname='', $middlename='', $lastname='', $homeaddress='', $telephone='', $birthday='', $birthplace='', $oaddress='', $otel='', $ofax='', $email='', $password='')
        $birthday = date("Y-m-d");
        $data = array(
                'sessionid' => $sessionid,
                'fname' => $firstname,
                'mname' => $middlename,
                'lname' => $lastname,
                'homeaddress' => $homeaddress,
                'telephone' => $telephone,
                'birthday' => $birthday,
                'birthplace' => $birthplace,
                'oaddress' => $oaddress,
                'otelephone' => $otel,
                'ofax' => $ofax,
                'email' => $email,
                'password' => $password,
                'regdate' => 'CURRENT_DATE'
        $this->db->insert('tmp_guestinfo', $data);
    //insert the vehicle information of the guest
    function insertgvinfo($sessionid,$regname, $regaddress, $year, $brand, $model, $platenum, $motornum, $chassisnum, $mvfnum, $color, $aog, $color, $aog, $tpl, $delivery, $insurance, $carType)
        $data = array(
                'sessionid' => $sessionid,
                'regname' => $regname,
                'regaddress' => $regaddress,
                'year' => $year,
                'brand' => $brand,
                'model' => $model,
                'platenum' => $platenum,
                'motornum' => $motornum,
                'motornum' => $chassisnum,
                'motornum' => $mvfnum,
                'color' => $color,
                'aog' => $aog,
                'tpl' => $tpl,
                'delivery' => $delivery,
                'insurance' => $insurance,
                'carType' => $carType
        $this->db->insert('tmp_guestvinfo', $data);

Make sure the 'birthday' field in the DB is 'date' type. (I assume you're using MySQL)
If you're running in localhost, check the server's time configuration too.

Also, I guess that $birthday = date("Y-m-d"); is there just as a test.

$birthday is actually a variable with existing date, with m-d-Y format, I'm trying to get it to mysql format, at first it got a value of 00-00-00 when posted, but now just kept showing the date today.

It's actually my first time converting date variable so I'm not sure how it works Big Grin

I think you want:
$birthday = date("Y-m-d",$timestamp);

The date() function defaults to today's date unless you pass it a second parameter.

Thanks! it helps.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.