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

Insert TIME only

Status
Not open for further replies.

HisMightiness

Programmer
Mar 17, 2004
54
US
Does anyone know how to insert the time into a DateTime field, and not allow the server to automatically add the date "1/1/1900"? I am using VBScript.
 
You could try ...

SET FieldName = CONVERT(Char,GetDate(),108)

Thanks

J. Kusch
 
Is that something to be done on the server? It doesn't look like a VBScript example. I need this to be able to be done at runtime.
 
That is a T-SQL command to enter the time only in a DateTime data type. If you are looking for the VB equivelent, you may need to post your question there.

If you have a date value that you are trying to add only the time portion into the field, replace the GetDate() function w/ your field name, as in ...


CONVERT(Char,MyDateField,108)

Thanks

J. Kusch
 
Jay, I'm guessing that he wants a datatime field with "no date". The date 1/1/1900 has a numerical value of 0. The server will put the time only into the datetime, but it will always be interpreted as a time after midnight 1/1/1900. You can take advantage of the fact that the numerical value of the date is 0 in some of the datetime functions. And for display you can use Jay's idea.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
That is very useful background information, donutman. Thanks! I went with a work-around from another site. I just need the time field to work a certain way while I am migrating some VBScript applications from Access to SQl, and then from VBScript to VB.Net. It had been somewhat challenging because each application needs to be migrated at a different pace and order. I appreciate your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top