Saturday, January 20, 2018

Solved - Convert varchar mm dd yyyy to dd mm yyyy - TSQL - SQL Server

Lets cast the varchar to date time first so that later we can use convert method.

@yourDate is in mm/dd/yyyy format 

select cast(@yourDate as datetime) 

eg

select cast('12/13/2017 10:10' as datetime) 

Now let's convert this to the desired date format of dd/mm/yyyy


select convert(varchar,CAST(@yourDate as datetime),103)

e.g.

select convert(varchar,CAST('12/13/2017 10:10' as datetime),103)
'

No comments:

Post a Comment

Recently Executed queries

 SELECT     txt.TEXT AS [SQL Statement],     qs.EXECUTION_COUNT [No. Times Executed],     qs.LAST_EXECUTION_TIME AS [Last Time Executed],   ...