Tom Schnaars
Tom Schnaars

Reputation: 58

facebook api date conversion

I am making my first app in codeigniter that draws birthdays from the facebook api and places them into a mysql database. The dates coming from the facebook api are 00-00-0000 and I need them to be converted to 0000-00-00.

I am using this bit of code to pull the data from facebook:

  try{
        $fql    =   "SELECT uid, name, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) AND strlen(birthday_date) > 0";
        $param  =   array(
            'method'    => 'fql.query',
            'query'     => $fql,
            'callback'  => ''
        );
        $fqlResult   =   $facebook->api($param);
    }
    catch(Exception $o){
        d($o);
    }
}  

I am using this bit of code to put the query from the api to mysql:

this->db->insert_batch('friends_birthdays', $fqlResult);

Do I need to escape the $fqlresult string first or is there something helpful in codeigniter that will help me do this? Sorry if this sounds stupid but I am a noob and any help would be greatly appreciated.

Thanks,

Tom

Upvotes: 1

Views: 745

Answers (1)

Ignas
Ignas

Reputation: 1965

You could use the date function with strtotime e.g.

<?php
  $fqlResult   =   $facebook->api($param);
  for($i=0;$i<count($fqlResult);$i++) {
      $fqlResult[$i]['birthday_date'] = date('Y-m-d', strtotime($fqlResult[$i]['birthday_date']));
  }
  $this->db->insert_batch('friends_birthdays', $fqlResult);
?>

Upvotes: 2

Related Questions