views:

49

answers:

2

Hi,

I'm trying to retrieve a UNIX timestamp from a query by combining a date and a time field in the table, however it keeps returning as zero.

            SELECT *, 
            UNIX_TIMESTAMP(startdate starttime) AS start,  
            UNIX_TIMESTAMP(enddate endtime) AS end
            FROM mytable; 

Can anyone help me out?

Thanks.

+4  A: 

Not tested but it should work:

SELECT UNIX_TIMESTAMP(CONCAT(startdate, ' ', starttime)) AS start;
Ionuț G. Stan
+1  A: 

Look at this:

mysql> select TIMESTAMP(curdate(), curtime()), TIMESTAMP(curdate(), curtime()) + 0;
+---------------------------------+-------------------------------------+
| TIMESTAMP(curdate(), curtime()) | TIMESTAMP(curdate(), curtime()) + 0 |
+---------------------------------+-------------------------------------+
| 2010-04-21 19:03:23             |                      20100421190323 |
+---------------------------------+-------------------------------------+
1 row in set (0.00 sec)

I am sorry, some addition:

mysql> select UNIX_TIMESTAMP(TIMESTAMP(curdate(), curtime())), UNIX_TIMESTAMP();
+-------------------------------------------------+------------------+
| UNIX_TIMESTAMP(TIMESTAMP(curdate(), curtime())) | UNIX_TIMESTAMP() |
+-------------------------------------------------+------------------+
|                                      1271862564 |       1271862564 |
+-------------------------------------------------+------------------+
1 row in set (0.00 sec)
newtover