DateTime2 против DateTime в SQL Server

Самый простой:

var milisegundos = parseInt (data.replace ("/ Date (", "") .replace (") /", "")); Var newDate = новая дата (milisegundos) .toLocaleDateString ("en-UE");

695
задан abatishchev 20 March 2017 в 19:25
поделиться

2 ответа

В документации MSDN для datetime рекомендуется использовать datetime2 . Вот их рекомендация:

Используйте время , дату , datetime2 и datetimeoffset типы данных для новых Работа. Эти типы соответствуют SQL Стандарт. Они более портативны. время , datetime2 и datetimeoffset обеспечить большую точность секунд. datetimeoffset указывает часовой пояс. поддержка глобально развернутых приложения.

datetime2 имеет больший диапазон дат, большую дробную точность по умолчанию и дополнительную точность, определяемую пользователем. Также, в зависимости от указанной пользователем точности, он может использовать меньше памяти.

610
ответ дан 22 November 2019 в 21:33
поделиться

DATETIME2 has a date range of "0001 / 01 / 01" through "9999 / 12 / 31" while the DATETIME type only supports year 1753-9999.

Also, if you need to, DATETIME2 can be more precise in terms of time; DATETIME is limited to 3 1/3 milliseconds, while DATETIME2 can be accurate down to 100ns.

Both types map to System.DateTime in .NET - no difference there.

If you have the choice, I would recommend using DATETIME2 whenever possible. I don't see any benefits using DATETIME (except for backward compatibility) - you'll have less trouble (with dates being out of range and hassle like that).

Plus: if you only need the date (without time part), use DATE - it's just as good as DATETIME2 and saves you space, too! :-) Same goes for time only - use TIME. That's what these types are there for!

477
ответ дан 22 November 2019 в 21:33
поделиться
Другие вопросы по тегам:

Похожие вопросы: