none
convert date ( yyyy-mm-dd) to date (mm-dd-yyyy)

    Question

  • could any body please let me know how i can convert convert date ( yyyy-mm-dd) to date (mm-dd-yyyy) in sql server 2008
    Thursday, February 11, 2010 7:19 PM

Answers

  • i think u have to try:

    DECLARE @date DATETIME
    select @date= '2009-02-01'
    SELECT CONVERT(NVARCHAR, @date, 103)

    Above is not safe, I'm afraid:
    SET LANGUAGE french
    DECLARE @date DATETIME
    select @date= '2009-02-01'
    SELECT CONVERT(NVARCHAR, @date, 103)
    GO
    SET LANGUAGE us_english
    DECLARE @date DATETIME
    select @date= '2009-02-01'
    SELECT CONVERT(NVARCHAR, @date, 103)

    Tibor Karaszi, SQL Server MVP | http://www.karaszi.com/sqlserver/default.asp | http://sqlblog.com/blogs/tibor_karaszi
    Sunday, February 14, 2010 9:40 AM

All replies

  • Can you give more context? Is the values stored ín some table? If so, what data type? Possibly, you can use the CONVERT function with an aproriate conversion code, or do the presentation at the client side. check out http://www.karaszi.com/SQLServer/info_datetime.asp for further explanations.
    Tibor Karaszi, SQL Server MVP | http://www.karaszi.com/sqlserver/default.asp | http://sqlblog.com/blogs/tibor_karaszi
    Thursday, February 11, 2010 8:03 PM
  • If you are interested in changing the date formats dynamically inside your query loops you can also write something like this and see how it works

    Declare @dates table

    (orig varchar(50)

    ,parsed datetime)

     

    SET DATEFORMAT mdy;

     

    insert into @dates

    select '2010-12-01','2010-12-01'

     

    SET DATEFORMAT dmy;

    insert into @dates

    select '2010-12-01','2010-12-01'

     

    select * from @dates

     

     

    -- So you can use the SET DATEFORMAT for your conversion

    -- If this is not wat you are looking for please add more info as mentioned by TIBORK


    Thanks, Leks
    Thursday, February 11, 2010 10:25 PM
  • Hi,

    Try this

    DECLARE @date DATETIME = '2009-02-01'
    SELECT CONVERT(NVARCHAR, @date, 101)

    Check this link for more info
    http://msdn.microsoft.com/en-us/library/ms187928.aspx


    Rajesh Jonnalagadda http://www.ggktech.com
    Friday, February 12, 2010 3:55 AM
  • Hi
    You can refer this article for all kind of date formats.

    Saturday, February 13, 2010 9:17 PM
  • i think u have to try:

    DECLARE @date DATETIME
    select @date= '2009-02-01'
    SELECT CONVERT(NVARCHAR, @date, 103)
    Sunday, February 14, 2010 8:29 AM
  • i think u have to try:

    DECLARE @date DATETIME
    select @date= '2009-02-01'
    SELECT CONVERT(NVARCHAR, @date, 103)

    Above is not safe, I'm afraid:
    SET LANGUAGE french
    DECLARE @date DATETIME
    select @date= '2009-02-01'
    SELECT CONVERT(NVARCHAR, @date, 103)
    GO
    SET LANGUAGE us_english
    DECLARE @date DATETIME
    select @date= '2009-02-01'
    SELECT CONVERT(NVARCHAR, @date, 103)

    Tibor Karaszi, SQL Server MVP | http://www.karaszi.com/sqlserver/default.asp | http://sqlblog.com/blogs/tibor_karaszi
    Sunday, February 14, 2010 9:40 AM