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

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL Server + Dates in ASP :(

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-10-10 : 09:28:58
Gerardo writes "Hi there:
my problem is: i'm developing a script that can obtain information but filter it with dates. You know: first date and final date or only one date.

But when I try to watch the page (yes, i use ASP) i don't get datas.

Example:
SELECT * FROM histdefectos WHERE fecha = '20020805'

ok, this query should had gave me all records with the 'fecha' field equal to '20020805'. The reality: I didn't obtain nothing.

Could you explain me how I have to programm my script to get records with the exactly day? Thanks anyway."

lozitskiy
Starting Member

28 Posts

Posted - 2002-10-10 : 10:13:11
First of all be sure that in database date is saved without minutes and etc.: 2002-10-10 00:00:00.000
Do not forget about date format mm/dd/yyyy or another (check on your sql server).


-------------
MCP MSSQL
Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2002-10-10 : 19:10:11
Try something like this.


SELECT *
FROM histdefectos
WHERE fecha Between '1/1/2002' AND '1/1/2003'

you can reuse it for only one date by having a where clause as such:
WHERE fecha Between '1/1/2002' AND '1/1/2002'

To convert your string you may want to use the CONVERT FUNCTION look it up in BOL.





Edited by - ValterBorges on 10/10/2002 19:10:56
Go to Top of Page

ashok
Yak Posting Veteran

57 Posts

Posted - 2002-10-11 : 03:56:19
datetime field also stores the time, so directly equating your date with the field date may not work very accurately.
You can cast the dates as integer to get correct date level comparisons :


where cast(fecha as integer) =
cast (Convert (DATETIME, '20020805', 112) as integer)


-ashok
http://www.unganisha.org
Go to Top of Page
   

- Advertisement -