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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date problem

Status
Not open for further replies.

choohean

Technical User
Jan 15, 2002
57
MY
I using asp to get time value and store in SQL server!
The problem I get is, the data I get save into SQL is like this 1/1/1900 1:30:56 am!

How do I get only the time value to save in SQL?
 
I dont know if you can

One way is to take the datepart of the value away from the datetime value

You must remember though that this is still thought of as a datetime value by SQL

and thus you will need to use a statement like

select convert (varchar (5),(datefield),108) from table


Hope this helps

Andy




 
I'm not sure that you can - but you can strip the date when you retrieve the info. Look up
Code:
DATEPART
. This is not a bug - it's an undocumented feature...
;-)
 
Never known it possible just to insert the time into SQL, but it shouldn't matter as you can just pull the time when you come to display your page.

Code:
<%FormatDateTime(date_field,3)%>
will just display the time once you've queried the datetime column from your database.

Craig
 
If you are determined to store only time, then one other way is to store the value in a non-datetime column, i.e. a varchar or an int. Depending on what subsequent calculations you might try to perform, this might work okay. But SQL Server will always store the date in a datetime column; if you don;t specify one, it will assign a default of 1900-01-01. But then it sometimes is just a simple matter of formatting, as others have mentioned above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top