SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creation Date Field in Sql Server
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Htwe Htwe
Starting Member

9 Posts

Posted - 07/05/2013 :  11:08:25  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3695 Posts

Posted - 07/05/2013 :  11:41:41  Show Profile  Reply with Quote
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 - 07/05/2013 :  11:48:21  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3695 Posts

Posted - 07/05/2013 :  13:02:15  Show Profile  Reply with Quote
You are very welcome - glad to help.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 07/07/2013 :  10:25:12  Show Profile  Reply with Quote
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 - 07/10/2013 :  12:17:38  Show Profile  Reply with Quote
Thanks a lot again.


Thanks And Regards
Htwe Htwe
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000