Results 1 to 4 of 4

Thread: datediff (today - date) for MS SQL

  1. #1
    Join Date
    Apr 2006
    Posts
    178

    datediff (today - date) for MS SQL

    Hello

    for MS SQL 2000

    I want to return the number of days between a date in the database and today

    something like
    Code:
    SELECT user.fName,
     user.lName & " (" & (datediff(now - user.lastVisit))  & " )" 
    FROM  user
    I must return

    John Turner (38)

    where 38 are the days between last visit and now

    thank you

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    select fname,lname, datediff(yy,hire_date,getdate()) as YearsofService from pubs..employee

  3. #3
    Join Date
    Apr 2006
    Posts
    178
    it works (with dd) thank you

  4. #4
    Join Date
    Aug 2006
    Location
    Bangalore
    Posts
    5
    Hi,
    Try this query

    SELECT CAST(LNAME AS VARCHAR(50)) + '(' + CAST(DATEDIFF(DD,LASTVISIT,GETDATE()) AS VARCHAR(3)) + ')' FROM USER

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •