Date difference in MySQL Oct25 '04

Here’s a handy reference that uses MySQL to find the number of days between two dates.

This is useful for job applications, where they ask you how many days you’ve worked at a particular place. What I do is keep a "Job Info" text file on my computer with all this information already computed. Then, when I go to fill out an application, I print the info and take it with me.

Bam. Done.

From the MySQL standpoint, this is obviously a popular thing to do, because as of version 4.1.1, there are explicit functions that do just that. But, as of this date, version 4.1.1 is not the release build, so I will mention another way to do it.

(As far as I know, 4.0.2 is the most stable release build.)

Prior to MySQL 4.1.1:

SELECT TO_DAYS('2004-11-08') - TO_DAYS('2004-07-26');
–> 105

As of MySQL 4.1.1:

SELECT DATEDIFF('2004-11-08','2004-07-26');
–> 105

The dates I used are just examples. Obviously, you can insert any dates in there, as long as the most recent date is listed first.

Categories: SQL

Add Feedback (view all)

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

I found solution using this query. This site is very easy understand things. This is very userfriendly. I just added this site to my favourites. ... Read more.

Well, Thanks to the site . I never knew what is the replacement of the dual of ORACLE in MySQL to test the in built functions of MySql Well ... Read more.

Popular Pages

  1. Fast rounded corners in Photoshop (7424 recent visits)
  2. PHP – passing variables across pages (2558 recent visits)
  3. JavaScript set selected on load (2414 recent visits)
  4. Removing all child nodes from an element (1828 recent visits)
  5. Firefox 3 smart address bar: wildcard search (1755 recent visits)
  6. iPod songs out of order? (1314 recent visits)
  7. Britney - Everytime piano tab (1138 recent visits)
  8. MySQL LEFT JOIN syntax (884 recent visits)
  9. Firefox 3 smart address bar: wildcard search (722 recent visits)
  10. Date difference in MySQL (651 recent visits)

Similar Entries

Stats

651 unique visits since July 2008

Syndicate

Advertisements