I am a bit confused as to the problems you are facing.
You first tell me that date is not giving you the correct outp]ut. Now you show that you actually use it in a number of functions.
The same is probably true for the $formatoldest value.
You have to check what you get from your database query (Which format) and then determine the correct steps to get you the value you need. Since we do not know what you want to do, it is a bit difficult to say.
So maybe you can reformulate your question, in a new thread, since the question you posed in this thread has been solved, ot my opinion.
Give us:
- The data you have (resultant of the query)
- The data you need / what you want to do.
J.