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

Learning Sql

Status
Not open for further replies.

opo

Programmer
Jul 30, 2001
56
US
Is there a function that will convert a date to a datetime?
 
There are not 2 separate data types, Date and Datetime, in SQL Server. They are all Datetime.

So if you don't specify a time along with a date, then the time is 12:00:00 AM or 00:00:00.
 
i am trying to compare a field with that has a timestamp with two fields one with the date the other with the time is there a function to combine them?
 

You can combine or concantenate columns (fields) in a query or T-SQL script. To provide the correct syntax, we need to know the data types and formats of the fileds or coulmns in the table.

For example, if the data types and formats are as follows...

Field1 - datetime
Field2 - char (mm/dd/yy)
Field3 - char (hh:mm:ss)

then the SQL script could be something like...

WHERE field1 = field2 + ' ' + field3

Or

If field1 = field2 + ' ' + field3
Print 'Match'
Else
Print 'No match'

Other data types and formats may require the use of the CONVERT function.

BTW: If field1 is a timestamp data type as you mentioned, you cannot compare it to dates and times as the timestamp data type doesn't really hold date and time data. It is simply a binary field, guaranteed to be unique. Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
 
Be careful - timestamp is not the same as a date and time. At least when I tried to implement it, the timestamp starts at 0 and all entries after that receive the amount of time after the first entry and no date. So if I entered the first one, and then a second one a second later, the timestamp for the second one was 00.00.01 and not the date and time of the entry. Maybe I didn't do something right, but that's what I encountered using 7.0.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top