Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch All Upcoming Facebook Friends Birthdays, not only for Current Year [duplicate]

Still i am getting List of Facebook Friends in Form of January to December in Ascending order, see below image:

But now i want to show List of Facebook Friends in Form of Upcoming Birthdays Like:

Recents on Top

I am using below query to fetch List of Friends:

   Log.d(LOG_TAG, "requestFriends(" + ")");
    Date date = new Date();
    String current_date = null;
    SimpleDateFormat dateFormatter = new SimpleDateFormat("MM-dd-yyyy");
    current_date = dateFormatter.format(date);
    System.out.println("Current Date is:- " + current_date);
    String query = "select name, birthday, uid, pic_square from user where uid in (select uid2 from friend where uid1=me()) and birthday_date>= "
    + current_date + " order by birthday_date";        

Please tell me what query i should use to fetch List in Form of Upcoming B'days

like image 666
ASMUIRTI Avatar asked Nov 24 '22 03:11

ASMUIRTI


1 Answers

This query will grab a list of all the friends in the logged in users account:

SELECT uid, name, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY birthday_date ASC

The pitfall of this is, you will need to check if the user has entered his/her birthday in their Facebook accounts.

A better query is (at least what I think is better):

SELECT uid, name, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) AND birthday_date >= '02/01' AND birthday_date <= '07/01' ORDER BY birthday_date ASC

This one gets just the list of users who have filled in their birthday's in their Facebook accounts. And with the use of ORDER BY birthday_date, they will always be with the upcoming birthday at the top going all the way down to the last one in the result set.

The pitfall of this is, and feel free to test it, I have never once got the entire years worth of birthdays using the second query. SO in my application, I call in 6 months of data at a time. This has been always precise and pretty much, bang on.

I suspect, the second query will suit your purpose considering that you need to show the upcoming birthday at the top of the list. To ensure you always get the current date and month for a precise result at all times, use this example (and a simple Google search or SO search will give you more) to get the current date and month:

http://www.asbhtechsolutions.com/android-tutorials/android-get-current-date-and-time

Then, concatenate a String and pass that instance as the query.

NOTE: The month and the date used in the query need to be double digits at all times.

like image 124
Siddharth Lele Avatar answered Jun 11 '23 03:06

Siddharth Lele