Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 Site Related Forums
 Article Discussion
 Article: Timestamps vs Datetime data types
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ask SQLTeam Question

0 Posts

Posted - 11/19/2000 :  10:25:43  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
saka writes "Hi there, gurus, I have a really tough question regarding an sql query involving dates. I have a table (links) containing a column with dates (gdate). When I run the following statement I won't get any records at all, just the fields:

SELECT * FROM links WHERE gdate = 2000-11-05

N.B. The table do have a record with the above date and it doesn't work with another date either. The field type is dbtimestamp. Greetings from Sweden"

Article Link.

Starting Member

0 Posts

Posted - 11/29/2000 :  04:49:01  Show Profile  Reply with Quote
Use your convet command

CONVERT(datetime, gDate, 101) = CONVERT(datetime, '11=01-2000', 101)

You may have problems the datetime stamp is a unique item to a database. Open SQL Query Analyzer and go to help. The look in T-SQL help...

The third input is a formatting code as listed below.
(yy) With


- 0 or 100 (*) Default mon dd yyyy hh:miAM (or PM)
1 101 USA mm/dd/yy
2 102 ANSI
3 103 British/French dd/mm/yy
4 104 German
5 105 Italian dd-mm-yy
6 106 - dd mon yy
7 107 - mon dd, yy
8 108 - hh:mm:ss
- 9 or 109 (*) Default + milliseconds mon dd yyyy hh:mi:ss:mmmAM (or PM)
10 110 USA mm-dd-yy
11 111 JAPAN yy/mm/dd
12 112 ISO yymmdd
- 13 or 113 (*) Europe default + milliseconds dd mon yyyy hh:mm:ss:mmm(24h)
14 114 - hh:mi:ss:mmm(24h)
- 20 or 120 (*) ODBC canonical yyyy-mm-dd hh:mi:ss(24h)
- 21 or 121 (*) ODBC canonical (with milliseconds) yyyy-mm-dd hh:mi:ss.mmm(24h)

Go to Top of Page

Starting Member

0 Posts

Posted - 12/04/2000 :  15:45:19  Show Profile  Reply with Quote
timestamp vs datetime

I sure wish that people would use timestamp and datetime correctly! There is a timestamp datatype that is much different than datetime.

Go to Top of Page

Starting Member

0 Posts

Posted - 12/05/2000 :  04:35:33  Show Profile  Reply with Quote
Functions in the where clause

You should always avoid using functions on columns in the where clause because it will remove the possibility of using an index, instead think a bit more about your sql i.e
use select *
from myTable
where myDateColumn >= '1 Jan 2000'
AND myDateColumn < '2 Jan 2000'

rather than
select *
from myTable
where LEFT( CONVERT(varchar, myDateColumn, 120), 10) = '2000-01-01'

Also note the usage of Jan rather than 1 number for the month, this eliminiates confusion caused by different language setups

Go to Top of Page

Patron Saint of Lost Yaks

30421 Posts

Posted - 03/20/2007 :  11:01:53  Show Profile  Visit SwePeso's Homepage  Reply with Quote
It will actually get you all records for the date '1905-06-08 00:00:00.000', it you execute it.

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 03/20/2007 :  12:11:37  Show Profile  Reply with Quote
Originally posted by Peso

It will actually get you all records for the date '1905-06-08 00:00:00.000', it you execute it.

Peter Larsson
Helsingborg, Sweden

Are there not enough current lost yaks? Do you have to dig them up from 6 years ago?

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000