harsha547
4/1/2017 - 10:22 AM

DATEFROMPARTS( Year , Month , Day ) will form a date from dateparts

DATEFROMPARTS( Year , Month , Day ) will form a date from dateparts

CREATE TABLE #DateTest
(
  Name VARCHAR(25),
  Day_of_Born INT,
  Month_of_Born INT,
  Year_of_Born INT
)

-- INSERT VALUES into the DateTest Table

INSERT INTO #DateTest VALUES('Harsha',30,03,1991);
INSERT INTO #DateTest VALUES('Ajay',12,08,1989);
INSERT INTO #DateTest VALUES('DJ',07,04,1988);


-- DATEFROMPARTS( Year , Month , Day ) will form a date from dateparts

SELECT Name , DATEFROMPARTS(Year_Of_Born, Month_of_Born, Day_of_Born) As DOB , 
			  DATENAME(Weekday,DATEFROMPARTS(Year_Of_Born, Month_of_Born, Day_of_Born)) As Week_Day,
			  FORMAT( DATEFROMPARTS(Year_Of_Born, Month_of_Born, Day_of_Born),'dddd') As Week_Day_2
	FROM #DateTest;





-- Linkedin Profile : https://www.linkedin.com/in/harshasannareddy/