0

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?

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks! true the field was showing null ( i don't know why) because i remember entering it in thru phpMyAdmin. Thanks anyway
1

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.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.