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. Date format in T-SQL

Date format in T-SQL

Scheduled Pinned Locked Moved Database
helpquestiondatabase
3 Posts 2 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.
  • W Offline
    W Offline
    Werries
    wrote on last edited by
    #1

    My dear friends, I’m battling with a major issue in T-SQL. I want to specify the format of a DateTime variable. In VB there is a command called ‘DateSerial’ that you can use to specify each value (Day, Month and Year) of the Date variable, but there is no such function in T-SQL. I live in South-Africa, and the date here is in the following order: Day, Month, Year. If I set a DateTime variable in this order - (SET @Date = ‘14/2/2007’) - the following error occurs: ‘The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.’ How can I solve this problem? Thanks, Werries

    A programmer's life is good... or is it?? Ek dink nie so nie!

    W M 2 Replies Last reply
    0
    • W Werries

      My dear friends, I’m battling with a major issue in T-SQL. I want to specify the format of a DateTime variable. In VB there is a command called ‘DateSerial’ that you can use to specify each value (Day, Month and Year) of the Date variable, but there is no such function in T-SQL. I live in South-Africa, and the date here is in the following order: Day, Month, Year. If I set a DateTime variable in this order - (SET @Date = ‘14/2/2007’) - the following error occurs: ‘The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.’ How can I solve this problem? Thanks, Werries

      A programmer's life is good... or is it?? Ek dink nie so nie!

      W Offline
      W Offline
      Werries
      wrote on last edited by
      #2

      Hi there, Thanks for those who had a look at my problem, but I've solved it. Just one simple sample on a previous post on this forum gaved me the answer. DECLARE @QAZ AS DATETIME SET DATEFORMAT dmy;SET @QAZ = '14-02-2007' print @QAZ Result: Feb 14 2007 12:00AM

      A programmer's life is good... or is it?? Ek dink nie so nie!

      1 Reply Last reply
      0
      • W Werries

        My dear friends, I’m battling with a major issue in T-SQL. I want to specify the format of a DateTime variable. In VB there is a command called ‘DateSerial’ that you can use to specify each value (Day, Month and Year) of the Date variable, but there is no such function in T-SQL. I live in South-Africa, and the date here is in the following order: Day, Month, Year. If I set a DateTime variable in this order - (SET @Date = ‘14/2/2007’) - the following error occurs: ‘The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.’ How can I solve this problem? Thanks, Werries

        A programmer's life is good... or is it?? Ek dink nie so nie!

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        I strongly recommend you use the ISO date format yyyyMMdd, interpretation of which is not subject to the locale or language settings of your SQL Server installation or the connection. So I would use SET @Date = '20070214'.

        Stability. What an interesting concept. -- Chris Maunder

        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