Welcome Guest, Not a member yet? Register   Sign In
inserting date problem
#1

[eluser]Corbee[/eluser]
Help!

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
Code:
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);
    }
#2

[eluser]gyo[/eluser]
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.
#3

[eluser]Corbee[/eluser]
$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
#4

[eluser]Jondolar[/eluser]
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.
#5

[eluser]Corbee[/eluser]
Thanks! it helps.




Theme © iAndrew 2016 - Forum software by © MyBB