Time Difference

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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Time Difference

Post by anjanesh »

I wanted to find out the no: of days elapsed since it was entered
select DATE_FORMAT(now()-20040807111937,"%D")
returns NULL.
I know DATE_SUB can be used but I was just wondering why this is returning null when now()-20040807111937 is returning a no:
Any Ideas ?
Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try using one of the diff or timestamp functions: http://dev.mysql.com/doc/mysql/en/Date_ ... tions.html
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Actually the solution to this is DATEDIFF(expr,expr2) which I discovered before posting. But its supported only from ver 4.1.1 and my host provides ver 3.23. So I've to code for that.

What can be done manually is something like
SELECT (20040807111937 - now()) /(3600 *24) giving the number of days
Post Reply