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. TSQL DATETIME

TSQL DATETIME

Scheduled Pinned Locked Moved Database
questiondatabasesql-servertoolshelp
4 Posts 3 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.
  • C Offline
    C Offline
    cdpace
    wrote on last edited by
    #1

    Hello guys, I am creating a database script and in this script i am declareing a datetime variable like below

    DECLARE @ENDDATE DATETIME

    Now my question is that i want to initialize the value of this variable and i am doing it this way

    SET @ENDATE '30/12/2009'

    and this is giving me an error saying that i cannot covert from char to datetime. How can this be done guys? Thank you in advance Regards, Christian Pace

    L W 2 Replies Last reply
    0
    • C cdpace

      Hello guys, I am creating a database script and in this script i am declareing a datetime variable like below

      DECLARE @ENDDATE DATETIME

      Now my question is that i want to initialize the value of this variable and i am doing it this way

      SET @ENDATE '30/12/2009'

      and this is giving me an error saying that i cannot covert from char to datetime. How can this be done guys? Thank you in advance Regards, Christian Pace

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      DECLARE @EndDate DATETIME
      SET @EndDate = '20091230'

      Something like this?

      I are Troll :suss:

      1 Reply Last reply
      0
      • C cdpace

        Hello guys, I am creating a database script and in this script i am declareing a datetime variable like below

        DECLARE @ENDDATE DATETIME

        Now my question is that i want to initialize the value of this variable and i am doing it this way

        SET @ENDATE '30/12/2009'

        and this is giving me an error saying that i cannot covert from char to datetime. How can this be done guys? Thank you in advance Regards, Christian Pace

        W Offline
        W Offline
        WoutL
        wrote on last edited by
        #3

        The default format of a date in sql = MM/dd/yyyy, so 30/12/2009 is indeed an invalid date. So there are three ways to solve this:

        • Use set DateFormat dmy
        • use set @EndDate = '12/30/2009'
        • use set @EndDate = '20091230'

        The first option will allow you to use your own way of using dates. In the second option you use the current settings of the server. You cannot always be sure of this setting, so I wouldn't use this. The third option is using the ISO format for dates. I prefer this method because it is language independent.

        Wout Louwers

        C 1 Reply Last reply
        0
        • W WoutL

          The default format of a date in sql = MM/dd/yyyy, so 30/12/2009 is indeed an invalid date. So there are three ways to solve this:

          • Use set DateFormat dmy
          • use set @EndDate = '12/30/2009'
          • use set @EndDate = '20091230'

          The first option will allow you to use your own way of using dates. In the second option you use the current settings of the server. You cannot always be sure of this setting, so I wouldn't use this. The third option is using the ISO format for dates. I prefer this method because it is language independent.

          Wout Louwers

          C Offline
          C Offline
          cdpace
          wrote on last edited by
          #4

          Thank you that did the trick! ;) thx for all the help

          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