Insert only dates into a column in sql server

Is there a way to insert only date in datetime column on sql server without time? eg

date (datetime)

================

12-01-2000

16-02-2000

or should I store this as varchar and cast when returning, so that I can convert whatever shape I need.

+3
source share
3 answers

My solution is to store it as varchar and convert it to datetime if necessary

SELECT CONVERT(VARCHAR(10),GETDATE(),111) -- get datepart onl y

or

also check this post about creating a date type:

create user-defined data types:

create type Date from dateTime

http://weblogs.sqlteam.com/jeffs/archive/2007/10/31/sql-server-2005-date-time-only-data-types.aspx

+2
source

SQLServer 2008, date.

SQL . , .

Select  Cast(Floor(Cast(MyDateColumn as float)) as DateTime) as MyDateColumn
From dbo.MyTable
+1

Source: https://habr.com/ru/post/1747133/


All Articles