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!

Syntax for getting datetime value in select statement

Status
Not open for further replies.

sfriedman451

Technical User
Apr 10, 2002
11
US
What is the best way to get values in a where clause from a datatime stamp data type without having to enter the full 2002-05-10 10:00:00. Is there a syntax that just allows me to enter a "where = '5/10/2002' or something like that?
 
Hi There,

Are you asking about a timestamp data type, or a datetime data type? They're not treated the same in SQL.

A timestamp is essentially a binary datatype that is not recognizable or equivalent to date/time.

MapMan

Assume nothing, question everything, be explicit not implicit, and you'll always be covered.
 
The syntax you used is acceptable. As long as you're not comparing to date fields. ie.

[tt]Select * from mytable where EntryDate = '05/02/2002'[/tt]

Would return records entered on May 2, 2002.

But,

[tt]Select * from mytable where EntryDate = GetDate()[/tt]

Would only return records that matched the date and time the query was run. In most cases, that means nothing would be returned.

If you wanted to return all the records for a specific date, try this...

[tt]Select * from mytable where DATEDIFF(Day, EntryDate, GetDate()) = 0[/tt]

HTH,

MapMan

Assume nothing, question everything, be explicit not implicit, and you'll always be covered.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top