简体   繁体   中英

How to return the time() value in Select SQL report query

I am wanting to retrieve the UNIX time() value of an order placed from within my store cart.

How do I get the Unix time from the time of order?

I have used the following queries however they are both returning incorrect information.

1) returns the word time() in the report, not the actual digital value.

DATE_FORMAT(T5.date_purchased, 'time()') As ref,  
returns:  time()

2) When I use the next option I get the current time, NOT the time of purchase.

DATE_FORMAT(T5.date_purchased, UNIX_TIMESTAMP()) As ref,
returns:  1421451235        17/01/2015 11:03  

Note:
I have checked against the following:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

Update
My query is based on this:

Select  

DATE_FORMAT(T5.date_purchased, '%Y-%m-%d') As ODate,  (works)  
(new line for Unix timestamp) eg: DATE_FORMAT(T5.date_purchased, UNIX_TIMESTAMP()) As ref,

From /*PREFIX*/products T1  
Inner Join /*PREFIX*/orders T5 On (T5.orders_id = T2.orders_id)

The 'ref' value was sent to the payment processing page from my cart, so it should be retrieved by SQL somehow. zen_draw_hidden_field('ref', time()) .

Making an answer from my comment as asked:

Solution is to use UNIX_TIMESTAMP() , which will return timestamp from the date/time value. So UNIX_TIMESTAMP(T5.date_purchased) should return timestamp of date purchased. To subtract hours use UNIX_TIMESTAMP(T5.date_purchased - interval 7 hour)

For further examples and usage see doc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM