Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 21st, 2012, 04:25 AM
Authorized User
 
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default date field

Hi there

I've got 2 x sql statements - the first one I want to pull out records between certain date ranges, the second I want to pull out records after their end date has passed.

This is what I've got set up for pulling out the records between certain date ranges:

SELECT * FROM tbl_tenders t WHERE t.startdate <= 21/07/2012 AND 21/07/2012 <= t.enddate AND IsLive = 0 ORDER BY t.startdate DESC

For the records whose enddate have passed I have:

SELECT * FROM tbl_tenders t WHERE 21/7/2012 > t.enddate

the enddate field I have in the database is a datetime field written such as: 2012-07-19 00:00:00.000 though not sure this should make any difference

What's happening is that all the records are being shown using the first sql statement regardless of the date

can any one advise?

thanks

Adam
 
Old July 22nd, 2012, 06:37 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

dates need to be strings they so they needs quotes. here is what a typical SQL statement that gets data between two dates looks like:

SELECT filedName FROM tbleName WHERE (dateTypeFieldName >= '7/21/2012') AND (dateTypeFieldName <= '8/22/2012')

Yours should be giving you an error, does it run like that....

Notice my is mm/dd/yyyy - We use dd/mm/yyyy here is aussie but I always query SQL Server in American format. using this function

Code:
  FUNCTION amDate(varDate)
      IF isNull(varDate) OR Trim(varDate) = "" OR varDate = "Null" THEN
        amDate = "Null"
      ELSE
        amDate = "'" & Day(DateValue(varDate)) & "/" & Month(DateValue(varDate)) & "/" & Year(DateValue(varDate)) & " " & TimeValue(varDate) & "'"
      END IF 
  END FUNCTION
so when you write your SQL do this:

Code:
sql = "SELECT filedName FROM tbleName WHERE (dateTypeFieldName >= " & amDate(request.form("dateFrom")) & ") AND (dateTypeFieldName <= " & amDate(request.form("dateTo")) & ")
NOTE - the amDate function placed single quotes arounf the value this is why I do this:

" & amDate(request.form("dateFrom")) & "

instead of this:

'" & amDate(request.form("dateFrom")) & "'
__________________
Wind is your friend
Matt
 
Old July 23rd, 2012, 04:23 AM
Authorized User
 
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default date field

thanks for your reply Matt - all sorted now.

sorry I posted twice, not sure which category it fell under.

thanks

Adam





Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating a Date field based on another field arholly Access VBA 6 November 22nd, 2006 11:19 AM
date field keyvanjan Classic ASP Databases 1 May 7th, 2005 02:32 AM
putting a date into a date field elladi Classic ASP Databases 2 March 31st, 2005 01:30 PM
Date Field from Parameter Field narooma.12 Crystal Reports 0 November 14th, 2004 08:51 PM
DTS Import ( Date string to Date field) gfowajuh SQL Server 2000 1 September 30th, 2003 06:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.