Format DateDiff or TimeDiff [SOLVED]

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Format DateDiff or TimeDiff [SOLVED]

Post by GeXus »

Does anyone know how to format datediff or timediff, I tried the following to format timediff, but it just returned null, which isnt accurate.

Code: Select all

SELECT content_id, DATEDIFF( created_dt, now( ) ) AS datediff, date_format( TIMEDIFF( created_dt, now( ) ) , '%H:%i' ) AS timediff
FROM content
Last edited by GeXus on Thu Feb 15, 2007 12:22 pm, edited 1 time in total.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Can you please be more specific about what your problem/question is?
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

I think i've got it... this ended up working for me

Code: Select all

SELECT content_id, DATEDIFF( created_dt, now( ) ) AS datediff, time_format( replace( TIMEDIFF( created_dt, now( ) ) , '-', '' ) , '%l' ) AS timediff
FROM content
The problem is that I want to display the following format '4 Days 3 Hours'. So I need to format the date and time appropriatly while using datediff, but the above worked.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

So the problem is solved? If so, please edit the post's title and change it from: Format DateDiff or TimeDiff to: Format DateDiff or TimeDiff [SOLVED] :wink:
Post Reply