SQL Server Date Hour format

sethindeed
01-10-2002, 01:46 PM
Okay
Here is my problem :
I am saving in an SQL Server database a Date Time Value (i.e : 01/10/02 15:15PM ) and I would like to be able to make a search on the date only via SQL language ( without considering the Time value ).
I tried about everything, from the LIKE keyword to the simple query ( Where Date = '01/10/02' )
It never returns any results because 01/10/02 is not the same time than 01/10/02 15:15PM ...
Anybody has a clue on how I can search the date value only ( and my program is already distributed, so it is a little bit too late to create a cloumn for date and another one for time...)
Thank you in advance...

PWNettle
01-10-2002, 01:48 PM
Have you tried using BETWEEN, as in

SELECT * FROM SomeTable WHERE SomeDateField BETWEEN '1/1/01' AND '12/31/01'

It's often a good way to deal with date ranges.

Paul

sethindeed
01-10-2002, 01:50 PM
Absolutely !
Thanx a lot !

Thinker
01-10-2002, 02:00 PM
After many questions about selecting by date from databases, I
have come to the conclusion that the only way to consistantly do
it is to always give the server a totally unambigous date.
'01/10/02' is about the most ambiguous date there is. Is it
02 Oct, 2001 or 10 Jan, 2002 or 01 Oct, 2002. There is no way
the server can read your mind so tell it exactly. Always use a four
digit year. I haven't tried, but I will bet it will work with either
2002/01/10 or 01/10/2002 (assuming your regional settings are
for mm/dd.) I still think the best, most unambigous format is just
10-Jan-2002 (replace Jan with whatever the month would be in
the local language.)

reboot
01-10-2002, 02:00 PM
You might also look up DatePart()

sethindeed
01-11-2002, 05:58 AM
Actually, we talked about garbage in garbage out.
I mean, all the dates are formatted the way I want when saving and retrieving, so there is no way I can get srewed there.
However, adding the Time parameter to an already distributed app gave me headache...

Thinker
01-11-2002, 07:34 AM
That could be an incorrect assumption, because a datetime field
doesn't 'remember' the format of the dates you stick in it. It is a
floating point numeric value. No months, days, years, hours, etc.
When you request any access to it, it has to be converted back to
an external format, or the date value you are trying to compare
has to be converted to the same internal format.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum