Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
GeXus
Forum Regular
Posts: 631 Joined: Sat Mar 11, 2006 8:59 am
Post
by GeXus » Thu Feb 15, 2007 11:32 am
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.
Oren
DevNet Resident
Posts: 1640 Joined: Fri Apr 07, 2006 5:13 am
Location: Israel
Post
by Oren » Thu Feb 15, 2007 11:56 am
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 » Thu Feb 15, 2007 12:03 pm
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.
Oren
DevNet Resident
Posts: 1640 Joined: Fri Apr 07, 2006 5:13 am
Location: Israel
Post
by Oren » Thu Feb 15, 2007 12:17 pm
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]