473,320 Members | 1,939 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DateDiff

Hi all.

I have to write an app that interacts with mySQL (I really must have done
some evil, evil stuff in a previous life to be landed with this!)

I need to work out the difference in days between values in the database and
the current date. "No problem," thought I , "I'll just use the SQL DATEDIFF
command." Heh! Well, the user interface I'm using didn't even recognise
DATEDIFF as being a function, so I decided to visit the mySQL website.

Their description of DATEDIFF is as follows:

------------------------
DATEDIFF(ARGUMENTS)
TIMEDIFF(ARGUMENTS)
[Rest of description to be added here]

NEED EXAMPLE
DATEDIFF() and TIMEDIFF() were added in MySQL 4.1.1.
------------------------

Wow! How helpful! I can't believe that they don't provided decent
documentation for their database server!

I had a quick Google, but couldn't find ANY pages describing how to use it,
only pages complaining about its non-existence in previous versions.

Can anyone help me here?

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.


Jul 19 '05 #1
6 16493
Since date values are just doubles in disguise, you can do simple arithmetic
on them. The difference in days is just Date2 - Date1, plus one if the count
is inclusive. If the dates include time values (the decimal part) you'll
need to convert to integer first.
"Lofty" <lo***@no.spam> wrote in message
news:Ms********************@wards.force9.net...
Hi all.

I have to write an app that interacts with mySQL (I really must have done
some evil, evil stuff in a previous life to be landed with this!)

I need to work out the difference in days between values in the database and the current date. "No problem," thought I , "I'll just use the SQL DATEDIFF command." Heh! Well, the user interface I'm using didn't even recognise
DATEDIFF as being a function, so I decided to visit the mySQL website.

Their description of DATEDIFF is as follows:

------------------------
DATEDIFF(ARGUMENTS)
TIMEDIFF(ARGUMENTS)
[Rest of description to be added here]

NEED EXAMPLE
DATEDIFF() and TIMEDIFF() were added in MySQL 4.1.1.
------------------------

Wow! How helpful! I can't believe that they don't provided decent
documentation for their database server!

I had a quick Google, but couldn't find ANY pages describing how to use it, only pages complaining about its non-existence in previous versions.

Can anyone help me here?

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.

Jul 19 '05 #2
Since date values are just doubles in disguise, you can do simple arithmetic
on them. The difference in days is just Date2 - Date1, plus one if the count
is inclusive. If the dates include time values (the decimal part) you'll
need to convert to integer first.
"Lofty" <lo***@no.spam> wrote in message
news:Ms********************@wards.force9.net...
Hi all.

I have to write an app that interacts with mySQL (I really must have done
some evil, evil stuff in a previous life to be landed with this!)

I need to work out the difference in days between values in the database and the current date. "No problem," thought I , "I'll just use the SQL DATEDIFF command." Heh! Well, the user interface I'm using didn't even recognise
DATEDIFF as being a function, so I decided to visit the mySQL website.

Their description of DATEDIFF is as follows:

------------------------
DATEDIFF(ARGUMENTS)
TIMEDIFF(ARGUMENTS)
[Rest of description to be added here]

NEED EXAMPLE
DATEDIFF() and TIMEDIFF() were added in MySQL 4.1.1.
------------------------

Wow! How helpful! I can't believe that they don't provided decent
documentation for their database server!

I had a quick Google, but couldn't find ANY pages describing how to use it, only pages complaining about its non-existence in previous versions.

Can anyone help me here?

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.

Jul 19 '05 #3
Thanks for the response, Jezebel.

However, I tried your logic, and according to mySQL, December 1st 2003 -
October 15 2003 = -20030995062807

which doesn't make an awful lot of sense to me - it certainly isn't the
difference in days! ;-)

Has anyone else managed to get the fabled mySQL DATEDIFF function to work?

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.

"Jezebel" <gr****@play.net> wrote in message
news:ec**************@TK2MSFTNGP12.phx.gbl...
Since date values are just doubles in disguise, you can do simple arithmetic on them. The difference in days is just Date2 - Date1, plus one if the count is inclusive. If the dates include time values (the decimal part) you'll
need to convert to integer first.
"Lofty" <lo***@no.spam> wrote in message
news:Ms********************@wards.force9.net...
Hi all.

I have to write an app that interacts with mySQL (I really must have done some evil, evil stuff in a previous life to be landed with this!)

I need to work out the difference in days between values in the database

and
the current date. "No problem," thought I , "I'll just use the SQL

DATEDIFF
command." Heh! Well, the user interface I'm using didn't even recognise DATEDIFF as being a function, so I decided to visit the mySQL website.

Their description of DATEDIFF is as follows:

------------------------
DATEDIFF(ARGUMENTS)
TIMEDIFF(ARGUMENTS)
[Rest of description to be added here]

NEED EXAMPLE
DATEDIFF() and TIMEDIFF() were added in MySQL 4.1.1.
------------------------

Wow! How helpful! I can't believe that they don't provided decent
documentation for their database server!

I had a quick Google, but couldn't find ANY pages describing how to use

it,
only pages complaining about its non-existence in previous versions.

Can anyone help me here?

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.


Jul 19 '05 #4
Thanks for the response, Jezebel.

However, I tried your logic, and according to mySQL, December 1st 2003 -
October 15 2003 = -20030995062807

which doesn't make an awful lot of sense to me - it certainly isn't the
difference in days! ;-)

Has anyone else managed to get the fabled mySQL DATEDIFF function to work?

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.

"Jezebel" <gr****@play.net> wrote in message
news:ec**************@TK2MSFTNGP12.phx.gbl...
Since date values are just doubles in disguise, you can do simple arithmetic on them. The difference in days is just Date2 - Date1, plus one if the count is inclusive. If the dates include time values (the decimal part) you'll
need to convert to integer first.
"Lofty" <lo***@no.spam> wrote in message
news:Ms********************@wards.force9.net...
Hi all.

I have to write an app that interacts with mySQL (I really must have done some evil, evil stuff in a previous life to be landed with this!)

I need to work out the difference in days between values in the database

and
the current date. "No problem," thought I , "I'll just use the SQL

DATEDIFF
command." Heh! Well, the user interface I'm using didn't even recognise DATEDIFF as being a function, so I decided to visit the mySQL website.

Their description of DATEDIFF is as follows:

------------------------
DATEDIFF(ARGUMENTS)
TIMEDIFF(ARGUMENTS)
[Rest of description to be added here]

NEED EXAMPLE
DATEDIFF() and TIMEDIFF() were added in MySQL 4.1.1.
------------------------

Wow! How helpful! I can't believe that they don't provided decent
documentation for their database server!

I had a quick Google, but couldn't find ANY pages describing how to use

it,
only pages complaining about its non-existence in previous versions.

Can anyone help me here?

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.


Jul 19 '05 #5
Heh!

Well, I've ended up using

TO_DAYS(departure_date) - TO_DAYS(CURDATE())

which works, but seems really, really nasty!

Is there a public.mysql.sucks newsgroup anywhere? ;-)

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.

"Lofty" <lo***@no.spam> wrote in message
news:1T********************@wards.force9.net...
Thanks for the response, Jezebel.

However, I tried your logic, and according to mySQL, December 1st 2003 -
October 15 2003 = -20030995062807

which doesn't make an awful lot of sense to me - it certainly isn't the
difference in days! ;-)

Has anyone else managed to get the fabled mySQL DATEDIFF function to work?

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.

"Jezebel" <gr****@play.net> wrote in message
news:ec**************@TK2MSFTNGP12.phx.gbl...
Since date values are just doubles in disguise, you can do simple

arithmetic
on them. The difference in days is just Date2 - Date1, plus one if the

count
is inclusive. If the dates include time values (the decimal part) you'll
need to convert to integer first.
"Lofty" <lo***@no.spam> wrote in message
news:Ms********************@wards.force9.net...
Hi all.

I have to write an app that interacts with mySQL (I really must have done some evil, evil stuff in a previous life to be landed with this!)

I need to work out the difference in days between values in the
database
and
the current date. "No problem," thought I , "I'll just use the SQL

DATEDIFF
command." Heh! Well, the user interface I'm using didn't even recognise DATEDIFF as being a function, so I decided to visit the mySQL website.

Their description of DATEDIFF is as follows:

------------------------
DATEDIFF(ARGUMENTS)
TIMEDIFF(ARGUMENTS)
[Rest of description to be added here]

NEED EXAMPLE
DATEDIFF() and TIMEDIFF() were added in MySQL 4.1.1.
------------------------

Wow! How helpful! I can't believe that they don't provided decent
documentation for their database server!

I had a quick Google, but couldn't find ANY pages describing how to

use it,
only pages complaining about its non-existence in previous versions.

Can anyone help me here?

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.



Jul 19 '05 #6
Heh!

Well, I've ended up using

TO_DAYS(departure_date) - TO_DAYS(CURDATE())

which works, but seems really, really nasty!

Is there a public.mysql.sucks newsgroup anywhere? ;-)

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.

"Lofty" <lo***@no.spam> wrote in message
news:1T********************@wards.force9.net...
Thanks for the response, Jezebel.

However, I tried your logic, and according to mySQL, December 1st 2003 -
October 15 2003 = -20030995062807

which doesn't make an awful lot of sense to me - it certainly isn't the
difference in days! ;-)

Has anyone else managed to get the fabled mySQL DATEDIFF function to work?

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.

"Jezebel" <gr****@play.net> wrote in message
news:ec**************@TK2MSFTNGP12.phx.gbl...
Since date values are just doubles in disguise, you can do simple

arithmetic
on them. The difference in days is just Date2 - Date1, plus one if the

count
is inclusive. If the dates include time values (the decimal part) you'll
need to convert to integer first.
"Lofty" <lo***@no.spam> wrote in message
news:Ms********************@wards.force9.net...
Hi all.

I have to write an app that interacts with mySQL (I really must have done some evil, evil stuff in a previous life to be landed with this!)

I need to work out the difference in days between values in the
database
and
the current date. "No problem," thought I , "I'll just use the SQL

DATEDIFF
command." Heh! Well, the user interface I'm using didn't even recognise DATEDIFF as being a function, so I decided to visit the mySQL website.

Their description of DATEDIFF is as follows:

------------------------
DATEDIFF(ARGUMENTS)
TIMEDIFF(ARGUMENTS)
[Rest of description to be added here]

NEED EXAMPLE
DATEDIFF() and TIMEDIFF() were added in MySQL 4.1.1.
------------------------

Wow! How helpful! I can't believe that they don't provided decent
documentation for their database server!

I had a quick Google, but couldn't find ANY pages describing how to

use it,
only pages complaining about its non-existence in previous versions.

Can anyone help me here?

--
Lofty
http://www.brainache.demon.co.uk

- There are 10 types of people in this world:
Those who understand binary, and those who don't.



Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: CJM | last post by:
I have an ASP page that lists files and folders in a directory. I'm using a cookie to record the last time this page was visited, and I intend to show links that are created/modified from that date...
8
by: inamori | last post by:
I face that problems 07/01/2003 06/30/2006 ---------> it should be 3 01/01/2003 02/28/2005 --------->could i get 2 years and 2 months 01/01/2003 03/01/2005 ...
1
by: intl04 | last post by:
I'm trying to set up a query that will include a new field ('Days until completion') whose value is derived from the DateDiff function. I think I have the syntax correct but am not sure. Days...
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
5
by: sr | last post by:
Anyone know of a better way to simulate a datediff for C#, i.e., without referencing the VB.NET runtime? Only added the functionality that was needed for me so it is not the full implementation...
6
by: kevinjwilson | last post by:
I am trying to get the date difference between two dates but I don't want the function to include weekends in the calculation. Does anyone have an idea on how to make this work?
2
by: muddasirmunir | last post by:
i am using vb 6 , i had place two datepicker in form now i want to calcuate differcen of month in two date for this i used the function datediff i had try it withh many syntax but getting error...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.