Im pulling a date from a database which is formatted like dd-mm-YYYY.
What I want to do is check the current date;
If you are looking for a generic way of doing this via MySQL, you could simply use a SELECT
statement, and add the WHERE
clause to it.
This will grab all fields for all rows, where the date stored in field "date" is before "now".
SELECT * FROM table WHERE UNIX_TIMESTAMP(`date`) < UNIX_TIMESTAMP()
Personally, I found this method to be more gentle on newbies in MySQL, since it uses the standard SELECT statement with WHERE to fetch the results. Obviously, you could grab only the fields relevant if you wanted to, by listing them instead of using a wildcard (*).
if(strtotime($row['database_date']) > strtotime('now')) echo $row['database_date'];
else echo date("d-m-Y");
No need to check the hours because if they are on the same day it will show the same date either way...
if (strtotime($date) > mktime(0,0,0))
should do the job.
a MySQL-only solution would be something like this:
SELECT IF (UNIX_TIMESTAMP(`field`) > UNIX_TIMESTAMP(), `field`,'GO AHEAD') as `yourdate`
FROM `table`