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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Sql server Date Diff

Sql server Date Diff

Scheduled Pinned Locked Moved Database
databasesql-serversysadmin
4 Posts 3 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.
  • P Offline
    P Offline
    Praveen029
    wrote on last edited by
    #1

    Hi, all select convert(varchar,(datediff(dd,'1979-09-04 12:34:50.603',getdate())/365)) here getdate()='2007-09-05 12:34:50.603' I need find the age of employee but this result is showing 28 instead of 27 because till one day is required to complete 27... Praveen Kumar

    F M 3 Replies Last reply
    0
    • P Praveen029

      Hi, all select convert(varchar,(datediff(dd,'1979-09-04 12:34:50.603',getdate())/365)) here getdate()='2007-09-05 12:34:50.603' I need find the age of employee but this result is showing 28 instead of 27 because till one day is required to complete 27... Praveen Kumar

      F Offline
      F Offline
      Frank Kerrigan
      wrote on last edited by
      #2

      How are you getting the age, Are you using DATEDIFF ?

      Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture) http://www.frankkerrigan.com/[^]

      1 Reply Last reply
      0
      • P Praveen029

        Hi, all select convert(varchar,(datediff(dd,'1979-09-04 12:34:50.603',getdate())/365)) here getdate()='2007-09-05 12:34:50.603' I need find the age of employee but this result is showing 28 instead of 27 because till one day is required to complete 27... Praveen Kumar

        M Offline
        M Offline
        Michael Potter
        wrote on last edited by
        #3

        Try something like this for a more accurate result:

        SELECT
            YEAR(GETDATE()) - YEAR('1979-09-04 12:34:50.603') - 
            CASE
                WHEN DATEPART(dayofyear,GETDATE()) < DATEPART(dayofyear,'1979-09-04 12:34:50.603') THEN 1
                ELSE 0
            END AS Age
        
        1 Reply Last reply
        0
        • P Praveen029

          Hi, all select convert(varchar,(datediff(dd,'1979-09-04 12:34:50.603',getdate())/365)) here getdate()='2007-09-05 12:34:50.603' I need find the age of employee but this result is showing 28 instead of 27 because till one day is required to complete 27... Praveen Kumar

          F Offline
          F Offline
          Frank Kerrigan
          wrote on last edited by
          #4

          Why do you use DATEDIFF(YY, @tartdate, getdate())

          Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture) http://www.frankkerrigan.com/[^]

          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