Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get rid of 12:00:00 AM in smalldatetime data type?

Status
Not open for further replies.

adonet

MIS
May 4, 2004
312
US
I insert date data only to SQL smalldatetime field and got :
5/29/2004 12:00:00 AM. How to get rid of 12:00:00 AM in smalldatetime data type?
 
Format() is working from "5/29/2004 12:00:00 AM " to "5/29/2004". But when insert into "5/29/2004" only, "5/29/2004 12:00:00 AM " will store in SQL server.
 
Look up "datetime and smalldatetime" in the T-SQL section of Books Online. It doesn't work that way. Both data types store the date and the time.

I'm not sure why it matters that it has 12:00 AM. If you don't want it, use a datatype in which you can store character data.
 
But when insert into "5/29/2004" only, "5/29/2004 12:00:00 AM " will store in SQL server.
If the column type in SQL server is a DateTime type, that's what will be stored.

You can use a SQL CONVERT function to only return you a date value (drop the time part), but more than likely I would just ignore it, and filter it out when you display it, not in your data-access layer.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Something I should have included in my earlier post is that this question falls into the common date/time area of how the storage of a date differs from the [/i]display[/i] of a date.

When you store a date (only) into a DB column of type DateTime, the database will automatically add a time value. The value it uses is 12AM (midnight). When you retrieve the date from the database, it's coming from a DateTime column, so of course it will have a time value on there. It'll be your job to format it for display.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top