Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql server convert date to string MM/DD/YYYY

I am using SQL Server 2008.

I have the following:

    select convert(varchar(20),fmdate) from Sery 

How do I convert the date to string such that it show as MM/DD/YYYY

like image 493
Nate Pet Avatar asked Aug 07 '12 22:08

Nate Pet


People also ask

How do you convert date format from Yyyymmdd to yyyy-mm-dd in sql?

Convert Char 'yyyymmdd' back to Date data types in SQL Server. Now, convert the Character format 'yyyymmdd' to a Date and DateTime data type using CAST and CONVERT. --A. Cast and Convert datatype DATE: SELECT [CharDate], CAST([CharDate] AS DATE) as 'Date-CAST', CONVERT(DATE,[CharDate]) as 'Date-CONVERT' FROM [dbo].

How do I change the date format in sql?

You can specify the format of the dates in your statements using CONVERT and FORMAT. For example: select convert(varchar(max), DateColumn, 13), format(DateColumn, 'dd-MMM-yyyy')


2 Answers

That task should be done by the next layer up in your software stack. SQL is a data repository, not a presentation system

You can do it with

CONVERT(VARCHAR(10), fmdate(), 101) 

But you shouldn't

like image 124
TFD Avatar answered Oct 05 '22 04:10

TFD


select convert(varchar(10), fmdate, 101) from sery 

101 is a style argument.

Rest of 'em can be found here.

T-SQL Cast / Convert date to string

like image 42
Tony Hopkinson Avatar answered Oct 05 '22 04:10

Tony Hopkinson