Исходный код вики Работа с датами
Редактировал(а) Alexandr Fokin 2023/12/16 14:12
Последние авторы
| author | version | line-number | content |
|---|---|---|---|
| 1 | |||
| 2 | Получить часть даты как число | ||
| 3 | **DATEPART ( datepart , date )** | ||
| 4 | https://docs.microsoft.com/ru-ru/sql/t-sql/functions/datepart-transact-sql?view=sql-server-ver15 | ||
| 5 | |||
| 6 | Получить форматированную дату как строку | ||
| 7 | **FORMAT ( value, format [, culture ] )** | ||
| 8 | https://docs.microsoft.com/ru-ru/sql/t-sql/functions/format-transact-sql?view=sql-server-ver15 | ||
| 9 | |||
| 10 | FORMAT([DATETIME], 'dd') | ||
| 11 | FORMAT([DATETIME], 'HH:mm') | ||
| 12 | |||
| 13 | |||
| 14 | Арифметические операции с датой (исходная дата +- указанное значение единиц времени) | ||
| 15 | **DATEADD (datepart , number , date )** | ||
| 16 | https://docs.microsoft.com/ru-ru/sql/t-sql/functions/dateadd-transact-sql?view=sql-server-ver15 | ||
| 17 | |||
| 18 | DATEADD(ss,numOfSeconds,DateField) | ||
| 19 | |||
| 20 | |||
| 21 | Разница между датами | ||
| 22 | **DATEDIFF (datepart , startdate , enddate )** | ||
| 23 | http://www.sql-tutorial.ru/ru/book_datediff_function.html | ||
| 24 | https://docs.microsoft.com/ru-ru/sql/t-sql/functions/datediff-transact-sql?view=sql-server-ver15 | ||
| 25 | |||
| 26 | DATEDIFF(ss,startDate,stopDate) | ||
| 27 | |||
| 28 | |||
| 29 | Задать дату | ||
| 30 | **DATEFROMPARTS (year, month, day)** | ||
| 31 | https://docs.microsoft.com/ru-ru/sql/t-sql/functions/datefromparts-transact-sql?view=sql-server-ver15 | ||
| 32 | |||
| 33 | |||
| 34 | Последний день месяца | ||
| 35 | **EOMONTH (start_date [, month_to_add ])** | ||
| 36 | https://docs.microsoft.com/ru-ru/sql/t-sql/functions/eomonth-transact-sql?view=sql-server-ver15 | ||
| 37 | |||
| 38 | EOMONTH ('12/1/2011') | ||
| 39 | |||
| 40 | |||
| 41 | Ссылки: | ||
| 42 | https://stackoverflow.com/questions/3480784/sql-server-add-seconds-to-a-datetime-field |