Home > Archive > MS SQL Server > February 2006 > problem with date time field ...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author problem with date time field ...
zerbie45@gmail.com

2006-02-28, 8:23 pm

Hi guys,

I have an asp page that needs to show data based on date criteria.
Basically the user selects a date and the asp page should display all
records within that day.
The problem is that this field contains date and time.

My current query is as follows:
RS.Open "Select * from DB1.dbo.logs WHERE Date = '" &
Request.Form("date") & "'", dbConn, 1

How should I modify this query so that it ignores the time ?

Thanks in advance !

Tibor Karaszi

2006-02-28, 8:23 pm

http://www.karaszi.com/SQLServer/info_datetime.asp
http://www.karaszi.com/SQLServer/in...e.asp#Searching

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www. solidqualitylearning
.com/

Blog: http:// solidqualitylearning
.com/blogs/tibor/



<zerbie45@gmail.com> wrote in message news:1141037700.450486.299340@p10g2000cwp.googlegroups.com...
> Hi guys,
>
> I have an asp page that needs to show data based on date criteria.
> Basically the user selects a date and the asp page should display all
> records within that day.
> The problem is that this field contains date and time.
>
> My current query is as follows:
> RS.Open "Select * from DB1.dbo.logs WHERE Date = '" &
> Request.Form("date") & "'", dbConn, 1
>
> How should I modify this query so that it ignores the time ?
>
> Thanks in advance !
>

zerbie45@gmail.com

2006-02-28, 8:23 pm

Hey Tibor,
thanks for your reply; I'm just starting using asp and sql.
Do you know a quick way to modify this query so that it skips the time
? Your links are a bit too advanced for me.
That would be VERY appreciated.

Thanks in advance.

Dan Guzman

2006-02-28, 8:23 pm

To add to Tibor's response, you can use a parameterized query to improve
performance, security and mitigate the need for date formatting. Also,
consider using a fast-forward cursor instead of a keyset one unless you have
a specific reason to do otherwise.

Set command = CreateObject("ADODB.Command")
command.ActiveConnection = connection
command.CommandText = _
"Select * from DB1.dbo.logs WHERE Date >= ? AND Date < ? + 1"

Set dateParameter1 = command.CreateParameter( _
"@dateParameter1", 7, 1)
command.Parameters.Append dateParameter1
dateParameter1.Value = Request.Form("date")
Set dateParameter2 = command.CreateParameter( _
"@dateParameter2", 7, 1)
command.Parameters.Append dateParameter2
dateParameter2.Value = Request.Form("date")

Set RS = command.Execute()

--
Hope this helps.

Dan Guzman
SQL Server MVP

<zerbie45@gmail.com> wrote in message
news:1141037700.450486.299340@p10g2000cwp.googlegroups.com...
> Hi guys,
>
> I have an asp page that needs to show data based on date criteria.
> Basically the user selects a date and the asp page should display all
> records within that day.
> The problem is that this field contains date and time.
>
> My current query is as follows:
> RS.Open "Select * from DB1.dbo.logs WHERE Date = '" &
> Request.Form("date") & "'", dbConn, 1
>
> How should I modify this query so that it ignores the time ?
>
> Thanks in advance !
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com