how to query get day from this date on sql? September 29, 2000 is Saturday I just want to take the day
i use query SELECT DATENAME(WEEKDAY, '2022-09-24')
result success : |Saturday|
but if i use query SELECT DATENAME(WEEKDAY, TGL_AKAD_MUR) from TABLE where FID_APLIKASI = 811213
this query error
how to solved my problem ?
CodePudding user response:
your data
DECLARE @TGLAKADMUR NVARCHAR(100)= N'24092022'
first you should change DDMMYYYY
to DD/MM/YYYY
with
SELECT @TGLAKADMUR,CONCAT(LEFT(@TGLAKADMUR, 2),'/',RIGHT(LEFT(@TGLAKADMUR, 4),2),'/',RIGHT(@TGLAKADMUR, 4))
then you should use convert(date,string,103)
to make your Nvarchar
to Date
SELECT Convert(date,CONCAT(LEFT(@TGLAKADMUR, 2),'/',RIGHT(LEFT(@TGLAKADMUR, 4),2),'/',RIGHT(@TGLAKADMUR, 4)),103);
then use DATENAME(WEEKDAY, date)
as follows:
SELECT DATENAME(WEEKDAY, Convert(date,CONCAT(LEFT(@TGLAKADMUR, 2),'/',RIGHT(LEFT(@TGLAKADMUR, 4),2),'/',RIGHT(@TGLAKADMUR, 4)),103))
CodePudding user response:
Use this query
select day(column_name) from tablename