Antonio Santos
Antonio Santos

Reputation: 39

How to save facebook birthday_date?

With FQL I get the birthdays in this way:

select uid, first_name, last_name, birthday_date from user where uid=me()

But then is showed in this format:

02/03/1942

And if I save it in a DATE field of my mysql database, it save 0000-00-00

How can I save this date in my mysql database ?

Upvotes: 0

Views: 738

Answers (1)

Lix
Lix

Reputation: 47986

Checkout this out- http://php.net/manual/en/function.date-create.php

<?php
  $test = new DateTime('02/31/2011');
  echo date_format($test, 'Y-m-d H:i:s'); // 2011-03-03 00:00:00
  $test = new DateTime('06/31/2011');
  echo date_format($test, 'Y-m-d H:i:s'); // 2011-07-01 00:00:00
?>

You can feed the DateTime() constructor a string that is similar to what Facebook returns and then use that object to format the date format that you need.


Alternatively, if you want an option consisting only of a MYSQL solution, you could simply pass the original date through STR_TO_DATE and feed it the current format. That will format the date for you in the correct way for a DATE field type.

INSERT INTO  `test` (  `date` ) 
  VALUES (
    STR_TO_DATE(  '02/03/1942',  '%d/%m/%Y' )
  )

Check out the documentation of STR_TO_DATE() for more details.

Upvotes: 2

Related Questions