DateDiff

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lofty

    #1

    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(ARGUME NTS)
    TIMEDIFF(ARGUME NTS)
    [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


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




  • Jezebel

    #2
    Re: DateDiff

    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" <lofty@no.spa m> wrote in message
    news:MsVib.1041 8$kA.2477698@wa rds.force9.net. ..[color=blue]
    > 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[/color]
    and[color=blue]
    > the current date. "No problem," thought I , "I'll just use the SQL[/color]
    DATEDIFF[color=blue]
    > 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(ARGUME NTS)
    > TIMEDIFF(ARGUME NTS)
    > [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[/color]
    it,[color=blue]
    > 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.
    >
    >
    >
    >[/color]


    Comment

    • Jezebel

      #3
      Re: DateDiff

      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" <lofty@no.spa m> wrote in message
      news:MsVib.1041 8$kA.2477698@wa rds.force9.net. ..[color=blue]
      > 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[/color]
      and[color=blue]
      > the current date. "No problem," thought I , "I'll just use the SQL[/color]
      DATEDIFF[color=blue]
      > 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(ARGUME NTS)
      > TIMEDIFF(ARGUME NTS)
      > [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[/color]
      it,[color=blue]
      > 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.
      >
      >
      >
      >[/color]


      Comment

      • Lofty

        #4
        Re: DateDiff

        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


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



        "Jezebel" <grocer@play.ne t> wrote in message
        news:ecfu80skDH A.2012@TK2MSFTN GP12.phx.gbl...[color=blue]
        > Since date values are just doubles in disguise, you can do simple[/color]
        arithmetic[color=blue]
        > on them. The difference in days is just Date2 - Date1, plus one if the[/color]
        count[color=blue]
        > is inclusive. If the dates include time values (the decimal part) you'll
        > need to convert to integer first.
        >
        >
        > "Lofty" <lofty@no.spa m> wrote in message
        > news:MsVib.1041 8$kA.2477698@wa rds.force9.net. ..[color=green]
        > > Hi all.
        > >
        > > I have to write an app that interacts with mySQL (I really must have[/color][/color]
        done[color=blue][color=green]
        > > 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[/color]
        > and[color=green]
        > > the current date. "No problem," thought I , "I'll just use the SQL[/color]
        > DATEDIFF[color=green]
        > > command." Heh! Well, the user interface I'm using didn't even[/color][/color]
        recognise[color=blue][color=green]
        > > DATEDIFF as being a function, so I decided to visit the mySQL website.
        > >
        > > Their description of DATEDIFF is as follows:
        > >
        > > ------------------------
        > > DATEDIFF(ARGUME NTS)
        > > TIMEDIFF(ARGUME NTS)
        > > [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[/color]
        > it,[color=green]
        > > 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.
        > >
        > >
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Lofty

          #5
          Re: DateDiff

          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


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



          "Jezebel" <grocer@play.ne t> wrote in message
          news:ecfu80skDH A.2012@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Since date values are just doubles in disguise, you can do simple[/color]
          arithmetic[color=blue]
          > on them. The difference in days is just Date2 - Date1, plus one if the[/color]
          count[color=blue]
          > is inclusive. If the dates include time values (the decimal part) you'll
          > need to convert to integer first.
          >
          >
          > "Lofty" <lofty@no.spa m> wrote in message
          > news:MsVib.1041 8$kA.2477698@wa rds.force9.net. ..[color=green]
          > > Hi all.
          > >
          > > I have to write an app that interacts with mySQL (I really must have[/color][/color]
          done[color=blue][color=green]
          > > 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[/color]
          > and[color=green]
          > > the current date. "No problem," thought I , "I'll just use the SQL[/color]
          > DATEDIFF[color=green]
          > > command." Heh! Well, the user interface I'm using didn't even[/color][/color]
          recognise[color=blue][color=green]
          > > DATEDIFF as being a function, so I decided to visit the mySQL website.
          > >
          > > Their description of DATEDIFF is as follows:
          > >
          > > ------------------------
          > > DATEDIFF(ARGUME NTS)
          > > TIMEDIFF(ARGUME NTS)
          > > [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[/color]
          > it,[color=green]
          > > 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.
          > >
          > >
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Lofty

            #6
            Re: DateDiff

            Heh!

            Well, I've ended up using

            TO_DAYS(departu re_date) - TO_DAYS(CURDATE ())

            which works, but seems really, really nasty!

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

            --
            Lofty


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



            "Lofty" <lofty@no.spa m> wrote in message
            news:1T7jb.1066 7$kA.2595615@wa rds.force9.net. ..[color=blue]
            > 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" <grocer@play.ne t> wrote in message
            > news:ecfu80skDH A.2012@TK2MSFTN GP12.phx.gbl...[color=green]
            > > Since date values are just doubles in disguise, you can do simple[/color]
            > arithmetic[color=green]
            > > on them. The difference in days is just Date2 - Date1, plus one if the[/color]
            > count[color=green]
            > > is inclusive. If the dates include time values (the decimal part) you'll
            > > need to convert to integer first.
            > >
            > >
            > > "Lofty" <lofty@no.spa m> wrote in message
            > > news:MsVib.1041 8$kA.2477698@wa rds.force9.net. ..[color=darkred]
            > > > Hi all.
            > > >
            > > > I have to write an app that interacts with mySQL (I really must have[/color][/color]
            > done[color=green][color=darkred]
            > > > 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[/color][/color][/color]
            database[color=blue][color=green]
            > > and[color=darkred]
            > > > the current date. "No problem," thought I , "I'll just use the SQL[/color]
            > > DATEDIFF[color=darkred]
            > > > command." Heh! Well, the user interface I'm using didn't even[/color][/color]
            > recognise[color=green][color=darkred]
            > > > DATEDIFF as being a function, so I decided to visit the mySQL website.
            > > >
            > > > Their description of DATEDIFF is as follows:
            > > >
            > > > ------------------------
            > > > DATEDIFF(ARGUME NTS)
            > > > TIMEDIFF(ARGUME NTS)
            > > > [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[/color][/color][/color]
            use[color=blue][color=green]
            > > it,[color=darkred]
            > > > 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.
            > > >
            > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Lofty

              #7
              Re: DateDiff

              Heh!

              Well, I've ended up using

              TO_DAYS(departu re_date) - TO_DAYS(CURDATE ())

              which works, but seems really, really nasty!

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

              --
              Lofty


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



              "Lofty" <lofty@no.spa m> wrote in message
              news:1T7jb.1066 7$kA.2595615@wa rds.force9.net. ..[color=blue]
              > 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" <grocer@play.ne t> wrote in message
              > news:ecfu80skDH A.2012@TK2MSFTN GP12.phx.gbl...[color=green]
              > > Since date values are just doubles in disguise, you can do simple[/color]
              > arithmetic[color=green]
              > > on them. The difference in days is just Date2 - Date1, plus one if the[/color]
              > count[color=green]
              > > is inclusive. If the dates include time values (the decimal part) you'll
              > > need to convert to integer first.
              > >
              > >
              > > "Lofty" <lofty@no.spa m> wrote in message
              > > news:MsVib.1041 8$kA.2477698@wa rds.force9.net. ..[color=darkred]
              > > > Hi all.
              > > >
              > > > I have to write an app that interacts with mySQL (I really must have[/color][/color]
              > done[color=green][color=darkred]
              > > > 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[/color][/color][/color]
              database[color=blue][color=green]
              > > and[color=darkred]
              > > > the current date. "No problem," thought I , "I'll just use the SQL[/color]
              > > DATEDIFF[color=darkred]
              > > > command." Heh! Well, the user interface I'm using didn't even[/color][/color]
              > recognise[color=green][color=darkred]
              > > > DATEDIFF as being a function, so I decided to visit the mySQL website.
              > > >
              > > > Their description of DATEDIFF is as follows:
              > > >
              > > > ------------------------
              > > > DATEDIFF(ARGUME NTS)
              > > > TIMEDIFF(ARGUME NTS)
              > > > [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[/color][/color][/color]
              use[color=blue][color=green]
              > > it,[color=darkred]
              > > > 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.
              > > >
              > > >
              > > >
              > > >[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              Working...