Hi
I could not help with the code. Somehow, you will have to handle it yourself because I don't know what plan you will get the expiration date from (note that one subscriber can subscribe for multiple plans, thus having different expiration date)
To check the expiration date of users, you will need to get data from to_date field in #__osmembership_subscribers table of that user. Please note that you should only get data from records which has published = 1 and user_id = ID_OF_CURRENT_USER
Hope it gives you some clues
Tuan