Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. get the difference between two dates

get the difference between two dates

Scheduled Pinned Locked Moved Database
databasehelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abdelhameed81
    wrote on last edited by
    #1

    hi all i need to get the difference between 2 dates so i use datediff function in SQL to get it but it doesn't work eveery time it get te same output even if i change the dates i don't know where is the problem select datediff(year,12/2/2000,getdate()) and the output is 106 tank abdelhameed81

    C 2 Replies Last reply
    0
    • A abdelhameed81

      hi all i need to get the difference between 2 dates so i use datediff function in SQL to get it but it doesn't work eveery time it get te same output even if i change the dates i don't know where is the problem select datediff(year,12/2/2000,getdate()) and the output is 106 tank abdelhameed81

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      abdelhameed81 wrote:

      select datediff(year,12/2/2000,getdate())

      Try putting the date inside apostrophes. Also, it is generally advisable to use the ISO format (yyyy-mm-dd) so that internationalisation problems don't arise. e.g. datediff(year, '2000-02-12', getdate())


      Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

      1 Reply Last reply
      0
      • A abdelhameed81

        hi all i need to get the difference between 2 dates so i use datediff function in SQL to get it but it doesn't work eveery time it get te same output even if i change the dates i don't know where is the problem select datediff(year,12/2/2000,getdate()) and the output is 106 tank abdelhameed81

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Just to further explain what happend. SQL Server interpreted 12/2/2000 as 12 divided by 2 divided by 2000 which is 0.003. Since the the calendar in SQL Server starts on 1st Janurary 1900 you had actually requested the difference in years between 04:19:20 on 1st January 1900 and midnight on 12th February 2006 (or 2nd December 2006 if you use the American format) which is 106.


        Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups