Anonymous user
Day of the week: Difference between revisions
→{{header|SQL}}: Added alternative approach that doesn't depend on localization parameters, such as date language.
Thundergnat (talk | contribs) m (→{{header|Icon}} and {{header|Unicon}}: Regularize non-standard header markup) |
(→{{header|SQL}}: Added alternative approach that doesn't depend on localization parameters, such as date language.) |
||
Line 4,408:
=={{header|SQL}}==
SQL has good support for date functions; care must be taken with NLS settings (globalization support), in the code below the date format language is passed in as an argument to the relevant function. (Or, see a variation that does not depend on language settings, after the output shown below.)
<lang sql>select extract(year from dt) as year_with_xmas_on_sunday
Line 4,415:
from dual
connect by level <= 2121 - 2008 + 1
)
where to_char(dt, 'Dy', 'nls_date_language=English') = 'Sun'
order by 1
Line 4,445 ⟶ 4,444:
17 rows selected.</pre>
Alternatively, the WHERE clause can be written in a way that avoids the complication of language settings. The (overloaded) TRUNC function, as applied to dates, takes a second argument indicating "to what" we must truncate. One option is 'iw' for "ISO week"; this truncates to the most recent Monday (the beginning of the ISO standard week, which is Monday through Sunday by definition). Like so (replace in the query above):
<lang sql>where dt - trunc(dt, 'iw') = 6
=={{header|Standard ML}}==
|