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. Extracting date part in SQL server

Extracting date part in SQL server

Scheduled Pinned Locked Moved Database
databasesql-serversysadminquestion
8 Posts 3 Posters 5 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.
  • T Offline
    T Offline
    ThaScorpion
    wrote on last edited by
    #1

    Dear all; I have a datetime field that stores data like "15/11/2006 10:12:23 AM" how can I extract the date part only without concatenating month and day and year inside the Sql statement as i have LOTs of data to be extracted. I tried to cast to char(10) and then convert to date but it was too slow. Thanx

    Scorpion

    J 1 Reply Last reply
    0
    • T ThaScorpion

      Dear all; I have a datetime field that stores data like "15/11/2006 10:12:23 AM" how can I extract the date part only without concatenating month and day and year inside the Sql statement as i have LOTs of data to be extracted. I tried to cast to char(10) and then convert to date but it was too slow. Thanx

      Scorpion

      J Offline
      J Offline
      Janani Divya
      wrote on last edited by
      #2

      ThaScorpion wrote:

      how can I extract the date part only

      Use the following in stored procedure, convert(varchar,checkindate,101) as checkindate This will extract only 15/11/2006 only. For ur reference: checkindate --> Field in the table. Hope u will understand it.

      Janani

      T 1 Reply Last reply
      0
      • J Janani Divya

        ThaScorpion wrote:

        how can I extract the date part only

        Use the following in stored procedure, convert(varchar,checkindate,101) as checkindate This will extract only 15/11/2006 only. For ur reference: checkindate --> Field in the table. Hope u will understand it.

        Janani

        T Offline
        T Offline
        ThaScorpion
        wrote on last edited by
        #3

        I mean extracting as date not just a string ! As converting to varchar ordering as date will fail !! If I will say "Order By convert(varchar,checkindate,101) as checkindate" the sort order will not be correct. Is there anything in SQL server that solves that problem ?? hope u understand it. Thank u

        Scorpion

        I J 2 Replies Last reply
        0
        • T ThaScorpion

          I mean extracting as date not just a string ! As converting to varchar ordering as date will fail !! If I will say "Order By convert(varchar,checkindate,101) as checkindate" the sort order will not be correct. Is there anything in SQL server that solves that problem ?? hope u understand it. Thank u

          Scorpion

          I Offline
          I Offline
          indianet
          wrote on last edited by
          #4

          use dateadd(day, datediff(day, 0, checkindate), 0) as checkindate to truncate the time value

          T 1 Reply Last reply
          0
          • I indianet

            use dateadd(day, datediff(day, 0, checkindate), 0) as checkindate to truncate the time value

            T Offline
            T Offline
            ThaScorpion
            wrote on last edited by
            #5

            Thank you indianet for your reply but i think i will face the same problem of speed. i didnt try it yet, but do u think it will not be slow ? There is a function in Access that do the solution in one step like : "Order by DateValue(CheckInDate)" and thats it ! there is nothing like that in Sql Server ?! thanx

            Scorpion

            1 Reply Last reply
            0
            • T ThaScorpion

              I mean extracting as date not just a string ! As converting to varchar ordering as date will fail !! If I will say "Order By convert(varchar,checkindate,101) as checkindate" the sort order will not be correct. Is there anything in SQL server that solves that problem ?? hope u understand it. Thank u

              Scorpion

              J Offline
              J Offline
              Janani Divya
              wrote on last edited by
              #6

              select convert(varchar,Reminder_date,101) as Reminder, Reminder_From, Reminder_Until, Reminder_AlarmTime, Create_dt, Update_dt from dbo.TBL_Reminder order by Reminder It was possible to order by date.

              Janani

              T 1 Reply Last reply
              0
              • J Janani Divya

                select convert(varchar,Reminder_date,101) as Reminder, Reminder_From, Reminder_Until, Reminder_AlarmTime, Create_dt, Update_dt from dbo.TBL_Reminder order by Reminder It was possible to order by date.

                Janani

                T Offline
                T Offline
                ThaScorpion
                wrote on last edited by
                #7

                Thanx alot till i Try it :rose:

                ThaScorpion

                J 1 Reply Last reply
                0
                • T ThaScorpion

                  Thanx alot till i Try it :rose:

                  ThaScorpion

                  J Offline
                  J Offline
                  Janani Divya
                  wrote on last edited by
                  #8

                  Have U order it by date?

                  Janani

                  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