tags:

views:

75

answers:

3

One of the fields in my database is of 'DATE' Type (field-name = 'post_date').

after fetching an array

$record = mysql_fetch_array($queryResult);

if I do

echo $record['post_date'];

I do not get any output (blank).

What should I do to properly handle the date type?

+2  A: 

If you get a blank output from doing that (and your query is non-broken), the problem is that the column value is NULL, not that there's anything wrong with the PHP interaction.

chaos
thanks! truethe field was showing null ( i don't know why) because i remember entering it in thru phpMyAdmin.Thanks anyway
OrangeRind
+1  A: 

This should work. Are you sure the fieldname is right, and that there's data in there?

As an aside: Dates are handled differently in MySQL and PHP:

  • PHP stores dates as unix time, i.e. number of seconds since 00:00:00 on Jan 1st, 1970.
  • MySQL stores them as Strings, like humans read them.

You can use the MySQL from_unixtime() and unix_timestamp() functions to convert back and forth as required.

Jeremy Smyth
A: 

The easiest way to parse a MySQL DATE or DATETIME field into a UNIX timestamp is by using strtotime.

shadowhand