Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2005
    Posts
    85

    Unanswered: convert style for datetime

    Hi,

    If the datetime value is '20.01.2006', what will be the style in CONVERT function ?

    Eg : select convert(datetime, '20.01.2006') gives datetime out-of-range error.

    There is no style provided for dd.mm.yyyy in SQL Server documentation. Is there any way to do such conversion with this constant value of format dd.mm.yyyy ?

    Please advice,

    Thanks,
    MiraJ

  2. #2
    Join Date
    Jun 2003
    Posts
    269

    Thumbs up

    Code:
    select convert(varchar, getdate(),104)
    I love cursor,though I never use it.Cos' I dont want to misuse it.
    ----------------------------------------------

    ----cheers
    ----http://mallier.blogspot.com

  3. #3
    Join Date
    Feb 2006
    Posts
    17

    Datetime

    Hi i have created a table in SQL server with a field 'datetime'. I would like to convert into date. I understand that the above sysntax does the trick...but it wher do u put the column name you want to convert...Could you please give me the full syntax!!
    Thanks

  4. #4
    Join Date
    Nov 2005
    Location
    San Francisco, CA
    Posts
    506
    Quote Originally Posted by migarich
    Hi i have created a table in SQL server with a field 'datetime'. I would like to convert into date. I understand that the above sysntax does the trick...but it wher do u put the column name you want to convert...Could you please give me the full syntax!!
    Thanks
    Here's the full syntax...
    convert(varchar(12),[field name],101)
    But plz read CONVERT on BOL
    Joydeep

  5. #5
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    47
    MiraJasmin,
    you can use
    Code:
     select convert(datetime, '20.01.2006', 104)
    migarich,
    To convert to datetime, the best way is to specify the datatime in YYYYMMDD.
    for example
    Code:
    insert into yourtable(yourdatetimefield)
    select '20060120'
    You can also use YYYY-MM-DD format

    To convert from datetime to format in string, the best way is actually do this in your front-end application. If you want to do this in T-SQL, then you can use
    Code:
    convert(varchar(30), yourdatetimefield, styleno)
    Refer to Books Online on the styleno
    -----------------
    KH


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •