You are here: Re: Date Range for SQL 2005 « MsSQL Server « IT news, forums, messages
Re: Date Range for SQL 2005

Posted by Plamen Ratchev on 07/12/07 23:13

The datetime data type includes both date and time portions. When you set a
datetime value to '4/5/07' (btw, it will be better to use format like
'20070405' to avoid ambiguity in date format), you are effectively setting
the time portion to midnight. So, your condition in plain English is like
"select all rows where ShipDate is after midnight on 4/5/07 and before
midnight on 4/18/07". I assume your ShipDate values have time portion
according to when the shipment occurred. Because of that all rows for 4/5/07
are returned (except if you had a shipment exactly at midnight).

If you want to get all rows between 4/5/07 and 4/18/07 (inclusive), you can
write it like this:

WHERE ShipDate >= '20070405'
AND ShipDate < '20070419'

See more about the datetime data type in the following article by Tibor
Karaszi:
http://www.karaszi.com/SQLServer/info_datetime.asp


HTH,

Plamen Ratchev
http://www.SQLStudio.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация