Решение
Запрошенный формат даты называется форматом ODBC (код 120 ).
Чтобы фактически вычислить запрошенные значения, включите в свой SQL следующее.
Копировать вставить...
DECLARE
@FirstDayOfLastMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, -1, GETDATE() - 2)) ), DATEADD(m, -1, GETDATE() - 1)))
, @LastDayOfLastMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(GETDATE()) ), GETDATE()))
... и используйте в своем коде:
- @FirstDayOfLastMonth
- @LastDayOfLastMonth
Имейте в виду, что он должен быть вставлен раньше, чем любые инструкции, которые ссылаются на параметры, но с этого момента вы можете ссылаться на @FirstDayOfLastMonth и @LastDayOfLastMonth в своем коде.
пример
Давайте посмотрим на код в действии:
DECLARE
@FirstDayOfLastMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, -1, GETDATE() - 2)) ), DATEADD(m, -1, GETDATE() - 1)))
, @LastDayOfLastMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(GETDATE()) ), GETDATE()))
SELECT
'First day of last month' AS Title, CONVERT(VARCHAR, @FirstDayOfLastMonth , 120) AS [ODBC]
UNION
SELECT
'Last day of last month' AS Title, CONVERT(VARCHAR, @LastDayOfLastMonth , 120) AS [ODBC]
Запустите приведенный выше код, чтобы получить следующий результат:
Примечание: имейте в виду, что сегодня для меня 12 сентября 2016 года .
Подробнее (для полноты картины)
Общие параметры даты
Вы хотите большего?
Чтобы настроить более широкий диапазон удобных параметров, связанных с датой, включите в свой SQL следующее:
DECLARE
@FirstDayOfCurrentWeek DATETIME = CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 0))
, @LastDayOfCurrentWeek DATETIME = CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 6))
, @FirstDayOfLastWeek DATETIME = CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 7, GETDATE()), 0))
, @LastDayOfLastWeek DATETIME = CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 7, GETDATE()), 6))
, @FirstDayOfNextWeek DATETIME = CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 7))
, @LastDayOfNextWeek DATETIME = CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 13))
, @FirstDayOfCurrentMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(GETDATE() - 1) ), GETDATE()))
, @LastDayOfCurrentMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, 1, GETDATE())) ), DATEADD(m, 1, GETDATE())))
, @FirstDayOfLastMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, -1, GETDATE() - 2)) ), DATEADD(m, -1, GETDATE() - 1)))
, @LastDayOfLastMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(GETDATE()) ), GETDATE()))
, @FirstDayOfNextMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, 1, GETDATE() - 1)) ), DATEADD(m, 1, GETDATE())))
, @LastDayOfNextMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, 2, GETDATE())) ), DATEADD(m, 2, GETDATE())))
, @FirstDayOfCurrentYear DATETIME = CONVERT(DATE, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0))
, @LastDayOfCurrentYear DATETIME = CONVERT(DATE, DATEADD(ms, -2, DATEADD(YEAR, 0, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0))))
, @FirstDayOfLastYear DATETIME = CONVERT(DATE, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) - 1, 0))
, @LastDayOfLastYear DATETIME = CONVERT(DATE, DATEADD(ms, -2, DATEADD(YEAR, 0, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0))))
, @FirstDayOfNextYear DATETIME = CONVERT(DATE, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0))
, @LastDayOfNextYear DATETIME = CONVERT(DATE, DATEADD(ms, -2, DATEADD(YEAR, 0, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 2, 0))))
Было бы разумно включить его раньше, желательно в начале вашей процедуры или SQL-запроса.
После объявления на параметры можно ссылаться в любом месте вашего кода столько раз, сколько вам нужно.
пример
Давайте посмотрим на код в действии:
DECLARE
@FirstDayOfCurrentWeek DATETIME = CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 0))
, @LastDayOfCurrentWeek DATETIME = CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 6))
, @FirstDayOfLastWeek DATETIME = CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 7, GETDATE()), 0))
, @LastDayOfLastWeek DATETIME = CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 7, GETDATE()), 6))
, @FirstDayOfNextWeek DATETIME = CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 7))
, @LastDayOfNextWeek DATETIME = CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 13))
, @FirstDayOfCurrentMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(GETDATE() - 1) ), GETDATE()))
, @LastDayOfCurrentMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, 1, GETDATE())) ), DATEADD(m, 1, GETDATE())))
, @FirstDayOfLastMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, -1, GETDATE() - 2)) ), DATEADD(m, -1, GETDATE() - 1)))
, @LastDayOfLastMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(GETDATE()) ), GETDATE()))
, @FirstDayOfNextMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, 1, GETDATE() - 1)) ), DATEADD(m, 1, GETDATE())))
, @LastDayOfNextMonth DATETIME = CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, 2, GETDATE())) ), DATEADD(m, 2, GETDATE())))
, @FirstDayOfCurrentYear DATETIME = CONVERT(DATE, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0))
, @LastDayOfCurrentYear DATETIME = CONVERT(DATE, DATEADD(ms, -2, DATEADD(YEAR, 0, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0))))
, @FirstDayOfLastYear DATETIME = CONVERT(DATE, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) - 1, 0))
, @LastDayOfLastYear DATETIME = CONVERT(DATE, DATEADD(ms, -2, DATEADD(YEAR, 0, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0))))
, @FirstDayOfNextYear DATETIME = CONVERT(DATE, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0))
, @LastDayOfNextYear DATETIME = CONVERT(DATE, DATEADD(ms, -2, DATEADD(YEAR, 0, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 2, 0))))
SELECT
'a) FirstDayOfCurrentWeek.' AS [Title] ,
@FirstDayOfCurrentWeek AS [DATE (Server default)] ,
CONVERT(VARCHAR, @FirstDayOfCurrentWeek, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @FirstDayOfCurrentWeek, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @FirstDayOfCurrentWeek, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @FirstDayOfCurrentWeek, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @FirstDayOfCurrentWeek, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @FirstDayOfCurrentWeek, 100) AS [U.S.] ,
CONVERT(VARCHAR, @FirstDayOfCurrentWeek, 120) AS [ODBC]
UNION
SELECT
'b) LastDayOfCurrentWeek.' AS [Title] ,
@LastDayOfCurrentWeek AS [DATE (Server default)] ,
CONVERT(VARCHAR, @LastDayOfCurrentWeek, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @LastDayOfCurrentWeek, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @LastDayOfCurrentWeek, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @LastDayOfCurrentWeek, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @LastDayOfCurrentWeek, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @LastDayOfCurrentWeek, 100) AS [U.S.] ,
CONVERT(VARCHAR, @LastDayOfCurrentWeek, 120) AS [ODBC]
UNION
SELECT
'c) FirstDayOfLastWeek.' AS [Title] ,
@FirstDayOfLastWeek AS [DATE (Server default)] ,
CONVERT(VARCHAR, @FirstDayOfLastWeek, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @FirstDayOfLastWeek, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @FirstDayOfLastWeek, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @FirstDayOfLastWeek, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @FirstDayOfLastWeek, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @FirstDayOfLastWeek, 100) AS [U.S.] ,
CONVERT(VARCHAR, @FirstDayOfLastWeek, 120) AS [ODBC]
UNION
SELECT
'd) LastDayOfLastWeek.' AS [Title] ,
@LastDayOfLastWeek AS [DATE (Server default)] ,
CONVERT(VARCHAR, @LastDayOfLastWeek, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @LastDayOfLastWeek, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @LastDayOfLastWeek, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @LastDayOfLastWeek, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @LastDayOfLastWeek, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @LastDayOfLastWeek, 100) AS [U.S.] ,
CONVERT(VARCHAR, @LastDayOfLastWeek, 120) AS [ODBC]
UNION
SELECT
'e) FirstDayOfNextWeek.' AS [Title] ,
@FirstDayOfNextWeek AS [DATE (Server default)] ,
CONVERT(VARCHAR, @FirstDayOfNextWeek, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @FirstDayOfNextWeek, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @FirstDayOfNextWeek, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @FirstDayOfNextWeek, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @FirstDayOfNextWeek, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @FirstDayOfNextWeek, 100) AS [U.S.] ,
CONVERT(VARCHAR, @FirstDayOfNextWeek, 120) AS [ODBC]
UNION
SELECT
'f) LastDayOfNextWeek.' AS [Title] ,
@LastDayOfNextWeek AS [DATE (Server default)] ,
CONVERT(VARCHAR, @LastDayOfNextWeek, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @LastDayOfNextWeek, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @LastDayOfNextWeek, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @LastDayOfNextWeek, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @LastDayOfNextWeek, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @LastDayOfNextWeek, 100) AS [U.S.] ,
CONVERT(VARCHAR, @LastDayOfNextWeek, 120) AS [ODBC]
UNION
SELECT
'g) FirstDayOfCurrentMonth.' AS [Title] ,
@FirstDayOfCurrentMonth AS [DATE (Server default)] ,
CONVERT(VARCHAR, @FirstDayOfCurrentMonth, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @FirstDayOfCurrentMonth, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @FirstDayOfCurrentMonth, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @FirstDayOfCurrentMonth, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @FirstDayOfCurrentMonth, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @FirstDayOfCurrentMonth, 100) AS [U.S.] ,
CONVERT(VARCHAR, @FirstDayOfCurrentMonth, 120) AS [ODBC]
UNION
SELECT
'h) LastDayOfCurrentMonth.' AS [Title] ,
@LastDayOfCurrentMonth AS [DATE (Server default)] ,
CONVERT(VARCHAR, @LastDayOfCurrentMonth, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @LastDayOfCurrentMonth, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @LastDayOfCurrentMonth, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @LastDayOfCurrentMonth, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @LastDayOfCurrentMonth, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @LastDayOfCurrentMonth, 100) AS [U.S.] ,
CONVERT(VARCHAR, @LastDayOfCurrentMonth, 120) AS [ODBC]
UNION
SELECT
'i) FirstDayOfLastMonth.' AS [Title] ,
@FirstDayOfLastMonth AS [DATE (Server default)] ,
CONVERT(VARCHAR, @FirstDayOfLastMonth, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @FirstDayOfLastMonth, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @FirstDayOfLastMonth, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @FirstDayOfLastMonth, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @FirstDayOfLastMonth, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @FirstDayOfLastMonth, 100) AS [U.S.] ,
CONVERT(VARCHAR, @FirstDayOfLastMonth, 120) AS [ODBC]
UNION
SELECT
'j) LastDayOfLastMonth.' AS [Title] ,
@LastDayOfLastMonth AS [DATE (Server default)] ,
CONVERT(VARCHAR, @LastDayOfLastMonth, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @LastDayOfLastMonth, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @LastDayOfLastMonth, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @LastDayOfLastMonth, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @LastDayOfLastMonth, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @LastDayOfLastMonth, 100) AS [U.S.] ,
CONVERT(VARCHAR, @LastDayOfLastMonth, 120) AS [ODBC]
UNION
SELECT
'k) FirstDayOfNextMonth.' AS [Title] ,
@FirstDayOfNextMonth AS [DATE (Server default)] ,
CONVERT(VARCHAR, @FirstDayOfNextMonth, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @FirstDayOfNextMonth, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @FirstDayOfNextMonth, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @FirstDayOfNextMonth, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @FirstDayOfNextMonth, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @FirstDayOfNextMonth, 100) AS [U.S.] ,
CONVERT(VARCHAR, @FirstDayOfNextMonth, 120) AS [ODBC]
UNION
SELECT
'l) LastDayOfNextMonth.' AS [Title] ,
@LastDayOfNextMonth AS [DATE (Server default)] ,
CONVERT(VARCHAR, @LastDayOfNextMonth, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @LastDayOfNextMonth, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @LastDayOfNextMonth, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @LastDayOfNextMonth, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @LastDayOfNextMonth, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @LastDayOfNextMonth, 100) AS [U.S.] ,
CONVERT(VARCHAR, @LastDayOfNextMonth, 120) AS [ODBC]
UNION
SELECT
'm) FirstDayOfCurrentYear.' AS [Title] ,
@FirstDayOfCurrentYear AS [DATE (Server default)] ,
CONVERT(VARCHAR, @FirstDayOfCurrentYear, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @FirstDayOfCurrentYear, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @FirstDayOfCurrentYear, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @FirstDayOfCurrentYear, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @FirstDayOfCurrentYear, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @FirstDayOfCurrentYear, 100) AS [U.S.] ,
CONVERT(VARCHAR, @FirstDayOfCurrentYear, 120) AS [ODBC]
UNION
SELECT
'n) LastDayOfCurrentYear.' AS [Title] ,
@LastDayOfCurrentYear AS [DATE (Server default)] ,
CONVERT(VARCHAR, @LastDayOfCurrentYear, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @LastDayOfCurrentYear, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @LastDayOfCurrentYear, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @LastDayOfCurrentYear, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @LastDayOfCurrentYear, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @LastDayOfCurrentYear, 100) AS [U.S.] ,
CONVERT(VARCHAR, @LastDayOfCurrentYear, 120) AS [ODBC]
UNION
SELECT
'o) FirstDayOfLastYear.' AS [Title] ,
@FirstDayOfLastYear AS [DATE (Server default)] ,
CONVERT(VARCHAR, @FirstDayOfLastYear, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @FirstDayOfLastYear, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @FirstDayOfLastYear, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @FirstDayOfLastYear, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @FirstDayOfLastYear, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @FirstDayOfLastYear, 100) AS [U.S.] ,
CONVERT(VARCHAR, @FirstDayOfLastYear, 120) AS [ODBC]
UNION
SELECT
'p) LastDayOfLastYear.' AS [Title] ,
@LastDayOfLastYear AS [DATE (Server default)] ,
CONVERT(VARCHAR, @LastDayOfLastYear, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @LastDayOfLastYear, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @LastDayOfLastYear, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @LastDayOfLastYear, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @LastDayOfLastYear, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @LastDayOfLastYear, 100) AS [U.S.] ,
CONVERT(VARCHAR, @LastDayOfLastYear, 120) AS [ODBC]
UNION
SELECT
'q) FirstDayOfNextYear.' AS [Title] ,
@FirstDayOfNextYear AS [DATE (Server default)] ,
CONVERT(VARCHAR, @FirstDayOfNextYear, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @FirstDayOfNextYear, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @FirstDayOfNextYear, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @FirstDayOfNextYear, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @FirstDayOfNextYear, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @FirstDayOfNextYear, 100) AS [U.S.] ,
CONVERT(VARCHAR, @FirstDayOfNextYear, 120) AS [ODBC]
UNION
SELECT
'r) LastDayOfNextYear.' AS [Title] ,
@LastDayOfNextYear AS [DATE (Server default)] ,
CONVERT(VARCHAR, @LastDayOfNextYear, 127) AS [ISO8601] ,
CONVERT(VARCHAR, @LastDayOfNextYear, 103) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [British&French] ,
CONVERT(VARCHAR, @LastDayOfNextYear, 104) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [German] ,
CONVERT(VARCHAR, @LastDayOfNextYear, 105) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Italian] ,
CONVERT(VARCHAR, @LastDayOfNextYear, 111) + ' ' + CONVERT(CHAR(5), @FirstDayOfCurrentWeek, 108) AS [Japan] ,
CONVERT(VARCHAR, @LastDayOfNextYear, 100) AS [U.S.] ,
CONVERT(VARCHAR, @LastDayOfNextYear, 120) AS [ODBC];
Запустите приведенный выше код, чтобы получить следующий результат:
Если ваша страна отсутствует, то это потому, что я не знаю ее кода. Было бы очень полезно отредактировать этот ответ и добавить новый столбец для своей страны.
Заранее спасибо.
Примечание: имейте в виду, что сегодня для меня 12 сентября 2016 года .
Ссылки
Для получения дополнительной информации о международном стандарте дат ISO8601 перейдите по этой ссылке:
Чтобы получить дополнительную информацию о международном стандарте дат ODBC, перейдите по этой ссылке:
Чтобы просмотреть список форматов даты, с которыми я работал, перейдите по этой ссылке:
Для дальнейшего чтения о типе данных DATETIME перейдите по этой ссылке: