Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL date format conversion to MMDDYYYY

What's the best way to convert the following statement to show the MMDDYYYY format such as 02022013 without slashes or hyphens...

CONVERT (CHAR(10), A.POKFRM, 112)
like image 331
khan16 Avatar asked Feb 02 '15 21:02

khan16


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].

Can you convert date to DateTime in sql?

We can convert the Date into Datetime in two ways. Using CONVERT() function: Convert means to change the form or value of something. The CONVERT() function in the SQL server is used to convert a value of one type to another type. Convert() function is used to convert a value of any type to another datatype.


Video Answer


1 Answers

You could take a formatting that gives you elements in order but with / or - and then replace the / or - to get your desired result.

select REPLACE(CONVERT (CHAR(10), getdate(), 101),'/','')

Result:

02022015
like image 126
SoulTrain Avatar answered Oct 03 '22 12:10

SoulTrain