I'm having a problem writing a query that formats a date. The problem is that not all my records include a date. Sometimes the date field will be NULL. So, when it tries to select the data from a record with a NULL date, the query results in 0 records. How can I write this query, so that it will give me a result even if the date field is NULL?
Here's my current query code:
Code: Select all
<?php
$query = "SELECT *, DATE_FORMAT(DateField, '%M %D, %Y') as DateField FROM table";
?>
Note: my date field is a MySQL date field (YYYY-MM-DD). Using PHP 4.3 and MySQL 3.23 on a Win2K/IIS machine.
I have a feeling that someone is going to say, "use a timestamp for your database instead of a date field." Well, that would probably work good, but I already have hundreds of records that have the date field format. Plus, I'd like to figure this out, to see if it can be done.
Any help would be appreciated!!!