Paul DuBois wrote:

At 22:27 +0200 5/16/04, John Fawcett wrote:

From: "T. H. Grejc"

 Hello,

 I'm trying to select all distinct years from a unixtimestamp field in
 MySQL database (3.23.56). I have a query:

 SELECT DISTINCT YEAR(date_field) As theYear FROM table

 but PHP gives me an empty array. What am I doing wrong?

 TNX

I think you need this function

    FROM_UNIXTIME(unix_timestamp,format).

Year does not operate on a unix timestamp.


Sure it does:

mysql> select t, year(t) from tsdemo1;
+----------------+---------+
| t              | year(t) |
+----------------+---------+
| 20010822133241 |    2001 |
| 20010822133241 |    2001 |
+----------------+---------+

The problem lies elsewhere.  Where that might be is difficult to
say, because no PHP code has been shown yet.

My DateField is in '1084415895' form, not in the '20010822133241' form, and the PHP is only regular mysql_fetch_array, then while loop, nothing special.


Is it maybe better to use 20010822133241 instead of unix_timestamp. I have allways used Unix timestamps, but never realy done any big date calculations. Is mysql TIMESTAMP(14) more flexibile that Unix timestamp.

TNX


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to