how to get just the date?

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

    #1

    how to get just the date?

    this is one thing that has always annyoed me in SQL is the lack of ability
    to get just the date of a datetime field... with SQL Server 2005 is there
    any easy and fast way to compare a date against another date excluding the
    time? thanks!


  • zacks@construction-imaging.com

    #2
    Re: how to get just the date?

    On Jul 9, 9:25 am, "Smokey Grindle" <nos...@nospam. comwrote:
    this is one thing that has always annyoed me in SQL is the lack of ability
    to get just the date of a datetime field... with SQL Server 2005 is there
    any easy and fast way to compare a date against another date excluding the
    time? thanks!
    This is really a question for the SQL Server group, but here is how I
    isolate the date part of a SQL Datatime column:

    left(convert(va rchar, datetimecolumnn ame, 120), 10)

    This is a SQL command, NOT a VB.NET command!!!

    This results in a date value in the format: YYYY-MM-DD.

    Comment

    • Daniel Bass

      #3
      Re: how to get just the date?

      This is one for SQL group, but I'm not sure what you mean...

      In SQL Server 2000 you can do a DateDiff on any element, so if you want to
      calculate the number of days from one day to the next you can simply do this
      with the DateDiff function.

      http://msdn2.microsoft.com/en-us/lib...9(sql.80).aspx



      "Smokey Grindle" <nospam@nospam. comwrote in message
      news:eHRpsyiwHH A.4384@TK2MSFTN GP02.phx.gbl...
      this is one thing that has always annyoed me in SQL is the lack of ability
      to get just the date of a datetime field... with SQL Server 2005 is there
      any easy and fast way to compare a date against another date excluding the
      time? thanks!
      >

      Comment

      • Smokey Grindle

        #4
        Re: how to get just the date?

        actually I posted it to the SQL group *scratches head* not sure how it ended
        up here

        <zacks@construc tion-imaging.comwrot e in message
        news:1183992105 .688509.317110@ q75g2000hsh.goo glegroups.com.. .
        On Jul 9, 9:25 am, "Smokey Grindle" <nos...@nospam. comwrote:
        >this is one thing that has always annyoed me in SQL is the lack of
        >ability
        >to get just the date of a datetime field... with SQL Server 2005 is there
        >any easy and fast way to compare a date against another date excluding
        >the
        >time? thanks!
        >
        This is really a question for the SQL Server group, but here is how I
        isolate the date part of a SQL Datatime column:
        >
        left(convert(va rchar, datetimecolumnn ame, 120), 10)
        >
        This is a SQL command, NOT a VB.NET command!!!
        >
        This results in a date value in the format: YYYY-MM-DD.
        >

        Comment

        • Rad [Visual C# MVP]

          #5
          Re: how to get just the date?

          On Mon, 9 Jul 2007 09:25:51 -0400, "Smokey Grindle"
          <nospam@nospam. comwrote:
          >this is one thing that has always annyoed me in SQL is the lack of ability
          >to get just the date of a datetime field... with SQL Server 2005 is there
          >any easy and fast way to compare a date against another date excluding the
          >time? thanks!
          >
          What you need is the convert function. You can pass as a parameter one
          of the formats that give you date only. Details are in SQL Server
          books online

          --

          Comment

          Working...