Display Day Name and Date from Date Column in SQL Server

elvisidrizi1
 
on Jul 03, 2021 11:57 AM
479 Views

Hi Everyone,

I did some google search regarding this issue and what i can find is all the seperate columns of Datepart and Datename.

what I need is a column in SQL where it shows the datename (Sunday as SUN) and the datepart (the no of the day)

for example:

Total - Day

250 - SUN/14

 

Best Regards,

Eidrizi

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jul 05, 2021 01:51 AM

Hi elvisidrizi1,

Check the below query.

SQL

DECLARE @Test AS TABLE(Total INT, DayTime DATETIME)
INSERT INTO @Test VALUES(250,'2021/06/30')
INSERT INTO @Test VALUES(130,'2021/07/05')

SELECT Total, 
	FORMAT(DayTime, 'ddd', 'en-US') + '/' + CONVERT(VARCHAR(5),DATEPART(DAY,DayTime)) AS 'Day'
FROM @Test

Output

Total   Day

250    Wed/30

130    Mon/5