Paweł Bąkiewicz
Paweł Bąkiewicz

Reputation: 207

facebook javascript sdk birthday format

Just simple quick questions,

I'm using facebook js api to login to my site

FB.login(function(response){

if (response.authResponse) {
FB.api('/me', function(response) { response.birthday .... }

Then I want to store birthday in my mysql db, but fb birhday format is MM/DD/YYYY and as far as I know mysql date format is YYYY-MM-DD. There is any other way then changing fb format by bruteforce ?

Upvotes: 1

Views: 2279

Answers (1)

phwd
phwd

Reputation: 19995

Use the Date object and its functions

var date = new Date(response.birthday);
var d = date.getDate()
var m = date.getMonth() + 1;
var y = date.getFullYear();
var format_date = '' + y + '-' + (m<=9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);

Upvotes: 1

Related Questions