0

I have a string b = "25/06/2013"; And I want to convert it to stored in SQL Server (data type=date) June, 25, 2013. Please advise me.

CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
darking050
  • 617
  • 1
  • 7
  • 20
  • http://stackoverflow.com/questions/1908394/mysql-using-a-string-column-with-date-text-as-a-date-field – Abs May 26 '14 at 07:08

6 Answers6

1

Please check whether this is fine,

SELECT DATENAME(MM, CONVERT(DATE, '25/06/2013', 104)) + RIGHT(CONVERT(VARCHAR(12), CONVERT(DATE, '25/06/2013', 104), 107), 9) AS Date_format
Suraj Singh
  • 4,041
  • 1
  • 21
  • 36
Praveena
  • 21
  • 1
0

SQL Server provide convert(), you have to store your data in varchar then use this function

CONVERT(VARCHAR(24),GETDATE(),113)

or

SELECT CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' +
       DATENAME(MM, GETDATE()) + ' ' + 
       RIGHT(CAST(YEAR(GETDATE()) AS VARCHAR(4)), 2) AS [DD Month YY]

http://www.sql-server-helper.com/tips/date-formats.aspx

Kevin Hogg
  • 1,771
  • 25
  • 34
Akash kumar
  • 981
  • 3
  • 14
  • 27
0

WIll this work,

SET DATEFORMAT DMY

DECLARE @DT VARCHAR(15) = '26/05/2014'
SELECT 
    DATENAME(MONTH,CAST(@DT AS DATETIME)) +','+
    CAST(DATEPART(DAY,CAST(@DT AS DATETIME)) AS VARCHAR(2))+','+
    CAST(DATEPART(YEAR,CAST(@DT AS DATETIME)) AS VARCHAR(4)) Dt
Jithin Shaji
  • 5,893
  • 5
  • 25
  • 47
0

Check out the below link of convert function which can be used:

http://www.w3schools.com/sql/func_convert.asp

Pranav Bilurkar
  • 955
  • 1
  • 9
  • 26
0

I wrote this useful extension method:

public static string ToSqlString(this DateTime dt) { return "CONVERT(DATETIME, '" + dt.Year + "-" + dt.Month + "-" + dt.Day + " " + dt.Hour + ":" + dt.Minute + ":" + dt.Second + "." + dt.Millisecond + "', 21 )"; }

Mojtaba
  • 2,764
  • 1
  • 21
  • 24
0

just check the below. There is format option available for as below link

Different dateformat in sqlserver :- http://www.sql-server-helper.com/sql-server-2008/sql-server-2008-date-format.aspx

you just change the 113 to desired value format as above in link.

declare @d datetime = getdate()

select CONVERT( varchar(11) , @d , 113)

Ajay2707
  • 5,690
  • 6
  • 40
  • 58