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. DateTime Conversion!!!

DateTime Conversion!!!

Scheduled Pinned Locked Moved Database
tutorial
3 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.
  • P Offline
    P Offline
    psamy
    wrote on last edited by
    #1

    Hi, How to cast the following value into datetime. select CAST('17/01/2006 14:52:48' as DATETIME) --> gives out-of-range datetime value.

    F M 2 Replies Last reply
    0
    • P psamy

      Hi, How to cast the following value into datetime. select CAST('17/01/2006 14:52:48' as DATETIME) --> gives out-of-range datetime value.

      F Offline
      F Offline
      Frank Kerrigan
      wrote on last edited by
      #2

      You are nearly there try this select Convert(DATETIME, '17/01/2006 14:52:48') There are options that you can use as well; as described below. example convertimg German date for today without time select Convert(DATETIME, CAST(Day(getdate())as char(2)) + '.' + CAST(Month(getdate()) as char(2)) + '.' + CAST(Year(getdate())as char(4)) , 104) Without century (yy) (1) With century (yyyy) Standard Input/Output (3) 0 or 100 (1, 2) Default mon dd yyyy hh:miAM (or PM) 1 101 U.S. mm/dd/yyyy 2 102 ANSI yy.mm.dd 3 103 British/French dd/mm/yy 4 104 German dd.mm.yy 5 105 Italian dd-mm-yy 6 106 (1) - dd mon yy 7 107 (1) - Mon dd, yy 8 108 - hh:mm:ss - 9 or 109 (1, 2) Default + milliseconds mon dd yyyy hh:mi:ss:mmmAM (or PM) 10 110 USA mm-dd-yy 11 111 JAPAN yy/mm/dd 12 112 ISO yymmdd 13 or 113 (1, 2) Europe default + milliseconds dd mon yyyy hh:mm:ss:mmm(24h) 14 114 - hh:mi:ss:mmm(24h) 20 or 120 (2) ODBC canonical yyyy-mm-dd hh:mi:ss(24h) 21 or 121 (2) ODBC canonical (with milliseconds) yyyy-mm-dd hh:mi:ss.mmm(24h) 126 (4) ISO8601 yyyy-mm-ddThh:mm:ss.mmm (no spaces) 127(6) ISO8601 with time zone Z. yyyy-mm-ddThh:mm:ss.mmmZ (no spaces) 130 (1, 2) Hijri (5) dd mon yyyy hh:mi:ss:mmmAM 131 (2) Hijri (5) dd/mm/yy hh:mi:ss:mmmAM -- modified at 7:05 Tuesday 8th August, 2006


      Look where you want to go not where you don't want to crash. Bikers Bible

      1 Reply Last reply
      0
      • P psamy

        Hi, How to cast the following value into datetime. select CAST('17/01/2006 14:52:48' as DATETIME) --> gives out-of-range datetime value.

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

        For consistent date-time conversion behaviour, always use the ISO format: yyyyMMdd hh:mm:ss. All other formats are subject to the user's current locale setting. Best practice when passing dates from an application into a query is to use parameterised queries with parameter objects. For example, in ADO.NET with SQL Server, use @name placeholders to mark the parameters, and SqlParameter objects to set the values of the parameters.

        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