Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Changing DATE format in SQL

$
0
0

Hi! I want to change the date format from MM-DD-YYYY  to YYYY-MM-DD in my SQL query.

Current Output:

http://s665.photobucket.com/user/veniceluvschoco/media/sql%202_zpsz56stteg.png.html

Desire Output:

http://s665.photobucket.com/user/veniceluvschoco/media/sql%201_zpsqrg0upro.png.html

Below is my current SQL Query:

create

table#t(SHIFTA_STARTdatetime,SHIFTA_ENDdatetime)


selectSHIFTA_START,


SHIFTA_END

,


casewhendatediff(d,CONVERT(DATETIME,LEFT(SHIFTA_START,17),103),CONVERT(DATETIME,LEFT(SHIFTA_END,17),103))>0then


 

dateadd(minute,23*60+59,dateadd(day,datediff(day,'20010101', CONVERT(DATETIME,LEFT(SHIFTA_START,17),103)),'20010101'))elseCONVERT(DATETIME,LEFT(SHIFTA_END,17),103)endasShiftTime

 

from[tablename].[dbo].[TMS_PEOPLE]

ANDCONVERT(DATETIME,LEFT(SHIFTA_START,17),103)!=''ANDCONVERT(DATETIME,LEFT(SHIFTA_END,17),103)!=''

Would appreciate if anyone out there could help! Thank you :-)


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>