Risky Wahyu N Risky Wahyu N - 4 months ago 10
Vb.net Question

SQL change day in my language in select statement

how i can change day in my language with select statemnt like use if
if day= sunday then set day = minggu

Answer

You need some kind of conversion. Take a look at example below:

WITH Src AS
(
    SELECT * FROM (VALUES
    (GETDATE()),
    (DATEADD(DAY, 1, GETDATE())),
    (DATEADD(DAY, 2, GETDATE())),
    (DATEADD(DAY, 3, GETDATE())),
    (DATEADD(DAY, 4, GETDATE())),
    (DATEADD(DAY, 5, GETDATE())),
    (DATEADD(DAY, 6, GETDATE()))
    ) T(Dates)
)
SELECT
    FORMAT(Dates, 'ddd', 'id-ID') LocalizedFormat,
    SUBSTRING('MingguSen   Sel   Rabu  Kamis Jumat Sabtu ', 6*(DATEPART(WEEKDAY,Dates)-1)+1, 6) LocalizedExpression
FROM Src

It results in:

LocalizedFormat     LocalizedExpression
---------------     -------------------
Kamis               Kamis 
Jumat               Jumat 
Sabtu               Sabtu 
Minggu              Minggu
Sen                 Sen   
Sel                 Sel   
Rabu                Rabu