Исходный код вики Работа с датами
Версия 6.1 от Alexandr Fokin на 2020/11/18 11:34
Скрыть последних авторов
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | |
| 2 | Получить часть даты как число | ||
| |
2.1 | 3 | **DATEPART ( datepart , date )** |
| 4 | https://docs.microsoft.com/ru-ru/sql/t-sql/functions/datepart-transact-sql?view=sql-server-ver15 | ||
| |
1.1 | 5 | |
| 6 | Получить форматированную дату как строку | ||
| |
2.1 | 7 | **FORMAT ( value, format [, culture ] )** |
| 8 | https://docs.microsoft.com/ru-ru/sql/t-sql/functions/format-transact-sql?view=sql-server-ver15 | ||
| |
1.1 | 9 | |
| |
2.1 | 10 | FORMAT([DATETIME], 'dd') |
| 11 | FORMAT([DATETIME], 'HH:mm') | ||
| 12 | |||
| 13 | |||
| |
6.1 | 14 | Арифметические операции с датой (исходная дата +- указанное значение единиц времени) |
| |
2.1 | 15 | **DATEADD (datepart , number , date )** |
| 16 | https://docs.microsoft.com/ru-ru/sql/t-sql/functions/dateadd-transact-sql?view=sql-server-ver15 | ||
| |
1.1 | 17 | |
| 18 | DATEADD(ss,numOfSeconds,DateField) | ||
| 19 | |||
| 20 | |||
| |
6.1 | 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 | |||
| |
4.1 | 29 | Задать дату |
| 30 | **DATEFROMPARTS (year, month, day)** | ||
| 31 | https://docs.microsoft.com/ru-ru/sql/t-sql/functions/datefromparts-transact-sql?view=sql-server-ver15 | ||
| |
1.1 | 32 | |
| |
5.1 | 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 | |||
| |
1.1 | 41 | Ссылки: |
| 42 | https://stackoverflow.com/questions/3480784/sql-server-add-seconds-to-a-datetime-field | ||
| 43 |