Transact-SQL: ottenere il giorno della settimana

DECLARE @DATA datetime
SET @DATA = '21/12/2012'</code>
 
SELECT
CASE (DATEPART(dw, @DATA) + @@DATEFIRST) % 7
WHEN 1 THEN 'Domenica'
WHEN 2 THEN 'Lunedì'
WHEN 3 THEN 'Martedì'
WHEN 4 THEN 'Mercoledì'
WHEN 5 THEN 'Giovedì'
WHEN 6 THEN 'Venerdì'
WHEN 0 THEN 'Sabato'
END

Note: @@DATEFIRST: restituisce il primo giorno della settimana come impostato da SET DATEFIRST e indica il primo giorno della settimana (il default per la lingua italiana è 1, per l’inglese stati uniti è il 7).

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>