[eluser]elambert[/eluser]
I am having trouble updating a MYSQL DATE field properly.
In the model, I get a retrieve a record with this function:
function get_by_user_id( $id )
{
$this->db->where( 'users_user_id', (int)$id );
$query = $this->db->get( 'profiles' );
if ( $query->num_rows() > 0 )
{
$row = $query->row_array();
$row[ 'profile_date_birth' ] = date( 'm-d-Y', strtotime( $row[ 'profile_date_birth' ] ) );
}
return ( $query->num_rows() > 0 ) ? $row : FALSE;
}
In the model, I update a record with this function:
function update( $id, $data )
{
$data[ 'profile_date_birth' ] = date( 'Y-m-d', strtotime( $data[ 'profile_date_birth' ] ) );
$this->db->where( 'profile_id', (int)$id );
$query = $this->db->update( 'profiles', $data );
return ( $query ) ? TRUE : FALSE;
}
So the profile_date_birth field has the value '2000-01-02' saved in the MYSQL DB. It is retrieved and displayed properly on the form as '01-02-2000'. If I save the field without changing it, it comes into the update function correctly as '01-02-2000', but after the date & strtotime conversion, the 'profile_date_birth' is as '2000-02-01' when it should be '2000-01-02'.
Any help would be appreciated.