Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creation Date Field in Sql Server

Author  Topic 

Htwe Htwe
Starting Member

9 Posts

Posted - 2013-07-05 : 11:08:25
Hello SqlTeam,

I want to store only date in database.I don't want to store time.

What data type do I use for storing date field only in sql server 2005?


Pls advice to me about it.

Thanks in advance

Htwe Htwe

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-05 : 11:41:41
In SQL 2005 there is no date/time type of data structure that will allow you to store only date part. What people do is to store the date and time with time as 00:00:00.000.

Other methods of storing - for example, storing the date as an interger number of days counted from a well-knownn starting date etc - have been used by some people, but those have their own baggage.

I would recommend using DATETIME or SMALLDATETIME data type, depending on the range.

If your source data is coming in with time portion as well, you can strip of the time portion using the following before stroing it into your table.:
DATEADD(dd,DATEDIFF(dd,0,YourSourceDate),0)
Go to Top of Page

Htwe Htwe
Starting Member

9 Posts

Posted - 2013-07-05 : 11:48:21
Yes Thanks a lot for giving advice to me how to define datetime data type.

Thanks And Regards
Htwe Htwe
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-05 : 13:02:15
You are very welcome - glad to help.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-07 : 10:25:12
quote:
Originally posted by Htwe Htwe

Yes Thanks a lot for giving advice to me how to define datetime data type.

Thanks And Regards
Htwe Htwe


This should give you idea on logic used

http://visakhm.blogspot.in/2012/07/generate-datetime-values-from-integers.html



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Htwe Htwe
Starting Member

9 Posts

Posted - 2013-07-10 : 12:17:38
Thanks a lot again.


Thanks And Regards
Htwe Htwe
Go to Top of Page
   

- Advertisement -