Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2003
    Location
    Pittsburgh, PA
    Posts
    86

    Question Unanswered: Getdate() with no time associated

    Is there a command that will let me set getdate() a in a smalldatetime field so that the there is no time associated with it?

    For example, I have a table that I want to load the date a user does an action. If I use getdate() I'll get a value such as 5/25/2006 08:26:56.340, whereas I would just like a value 5/25/2006.

    I can work it out by doing the following: select (datename(month,getdate())+'-'+datename(day,getdate())+'-'
    +datename(year,getdate()))

    However it seems to me that there should be a simpler way.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    well, i dunno if it's simpler, but this is a lot more efficient --

    dateadd(d,datediff(d,0,getdate()),0)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Towards the bottom of this article is an explanation on the why and how

    EDIT - how about I post the article link eh?
    http://www.sql-server-performance.com/fk_datetime.asp
    Testimonial:
    pootle flump
    ur codings are working excelent.

  4. #4
    Join Date
    Jan 2003
    Location
    Pittsburgh, PA
    Posts
    86

    Thanks to you both

    That does seem more efficient (I knew there had to be a better approach). And thanks for the link to the article.

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    fabulous link, pootle, thanks
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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