Farzan Najipour
Farzan Najipour

Reputation: 2503

Mariadb - calculate date difference in hour

Here is my initial code :

SELECT order_logs.order_logs_created, DATEDIFF(HOUR ,NOW(),order_logs.order_logs_created) FROM order_logs

And I gave an error :

#1582 - Incorrect parameter count in the call to native function 'DATEDIFF'

Then , I searched about MariaDB's DATEDIFF and I saw this , I figured out that I can use DATEDIFF with two parameters so I remove HOUR :

SELECT order_logs.order_logs_created, DATEDIFF(NOW(),order_logs.order_logs_created) FROM order_logs

I need time difference in hours , Actually it gives me in days. Any suggestion?

Upvotes: 1

Views: 5654

Answers (2)

Gurwinder Singh
Gurwinder Singh

Reputation: 39497

You can use TIMESTAMPDIFF for this:

SELECT 
    order_logs.order_logs_created,
    TIMESTAMPDIFF(HOUR,
        order_logs.order_logs_created,
        NOW())
FROM
    order_logs

Upvotes: 3

Farzan Najipour
Farzan Najipour

Reputation: 2503

Use TIMESTAMPDIFF:

SELECT order_logs.order_logs_created, TIMESTAMPDIFF(HOUR ,order_logs.order_logs_created , NOW()) FROM order_logs

Upvotes: 0

Related Questions