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. Convert a String into datetime

Convert a String into datetime

Scheduled Pinned Locked Moved Database
databasehelptutorial
4 Posts 4 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.
  • N Offline
    N Offline
    NET India
    wrote on last edited by
    #1

    Hello Friends, I've a date in string variable i want to convert this string into datetime format(mm/dd/yyyy) but it's giving me an error. Because my date is stored in dd/mm/yyyy but sql analyser require datetime in mm/dd/yyyy. So please suggest me the way. Here is my example Declare @str varchar(100),@strDate datetime Set @str='14/02/2010'--(dd/mm/yyyy) Set @strDate=@str Print @strDate

    M N K 3 Replies Last reply
    0
    • N NET India

      Hello Friends, I've a date in string variable i want to convert this string into datetime format(mm/dd/yyyy) but it's giving me an error. Because my date is stored in dd/mm/yyyy but sql analyser require datetime in mm/dd/yyyy. So please suggest me the way. Here is my example Declare @str varchar(100),@strDate datetime Set @str='14/02/2010'--(dd/mm/yyyy) Set @strDate=@str Print @strDate

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Use the following

      Declare @str varchar(100),@strDate datetime
      Set @str='14/02/2010'--(dd/mm/yyyy)
      Set @strDate=CONVERT(DATETIME, @str,103)
      Print @strDate

      Look into CONVERT in BOL

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • N NET India

        Hello Friends, I've a date in string variable i want to convert this string into datetime format(mm/dd/yyyy) but it's giving me an error. Because my date is stored in dd/mm/yyyy but sql analyser require datetime in mm/dd/yyyy. So please suggest me the way. Here is my example Declare @str varchar(100),@strDate datetime Set @str='14/02/2010'--(dd/mm/yyyy) Set @strDate=@str Print @strDate

        N Offline
        N Offline
        Niladri_Biswas
        wrote on last edited by
        #3

        Try this

        Declare @str varchar(100)
        Set @str='14/02/2010'--(dd/mm/yyyy)
        select ConvertedDate = CONVERT(varchar(10),CONVERT(datetime,@str,103),101)--mm/dd/yyyy

        Output:

        ConvertedDate
        02/14/2010

        :)

        Niladri Biswas

        1 Reply Last reply
        0
        • N NET India

          Hello Friends, I've a date in string variable i want to convert this string into datetime format(mm/dd/yyyy) but it's giving me an error. Because my date is stored in dd/mm/yyyy but sql analyser require datetime in mm/dd/yyyy. So please suggest me the way. Here is my example Declare @str varchar(100),@strDate datetime Set @str='14/02/2010'--(dd/mm/yyyy) Set @strDate=@str Print @strDate

          K Offline
          K Offline
          Karan_TN
          wrote on last edited by
          #4

          try the below

          SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY]

          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