0

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.

2 Answers 2

4

Not tested but it should work:

SELECT UNIX_TIMESTAMP(CONCAT(startdate, ' ', starttime)) AS start;
Sign up to request clarification or add additional context in comments.

Comments

1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.