Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. 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 Databases 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
  #1 (permalink)  
Old October 4th, 2007, 10:48 AM
Authorized User
Points: 292, Level: 5
Points: 292, Level: 5 Points: 292, Level: 5 Points: 292, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: , , .
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date Comparison

I'm using ASP and a MSSql database. What I need to do is run a report where the transaction is dated between two dates. For example: I want a report of any transaction between 10/1/2007 at 5:00 pm and 10/3/2007 at 10:15 am.

What's the best way to do this. My end users are entering their requests with a date field and a time field.

Thanks in advance for any help.
  #2 (permalink)  
Old October 4th, 2007, 11:30 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Your query would look something like this:

SELECT * from [table] where [date] between '10/01/2007 5:00 PM' AND '10/03/2007 10:15 AM'

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Beginning Visual C# 2008
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========
  #3 (permalink)  
Old October 4th, 2007, 04:10 PM
Authorized User
Points: 292, Level: 5
Points: 292, Level: 5 Points: 292, Level: 5 Points: 292, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: , , .
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One more quick question, since my users are entering two separate variables for date and time, is there any way to join them? For example: datenum=10/3/2007 and timenum=05:00. Will a "&" join them for a date variable?

THANKS!!
  #4 (permalink)  
Old October 4th, 2007, 04:47 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

If you are doing it in code, a simple sting can be passed into a stored proc for a datetime field, as long as it is a valid date time so:

string sDate = txtDate.Text + " " + txtTime.Text; //let txtDate == 10/3/2007 and let time == 05:00

result 10/3/2007 05:00

the & will work in VB but not in C#, C# uses the + as the concatenation operator as demonstrated above.

hth

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Beginning Visual C# 2008
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========
  #5 (permalink)  
Old October 5th, 2007, 04:32 PM
Authorized User
Points: 292, Level: 5
Points: 292, Level: 5 Points: 292, Level: 5 Points: 292, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: , , .
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm using VB and ASP and MSSql, will the above work for that?

  #6 (permalink)  
Old October 5th, 2007, 05:39 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

>< I am so sorry. I am used to trolling the ASP.NET/C#/VB.NET forums that i posted C# code. Wow.

You would have to do something like this:

Dim sDate1
Dim sDate2
Dim sSql

sDate1 = CStr(Request.Form("txtDate1")) & " " & CStr(Request.Form("txtTime1"))
sDate2 = CStr(Request.Form("txtDate2")) & " " & CStr(Request.Form("txtTime2"))
sSql = "SELECT * from [table] where [date] between '" & sDate1 & "' AND '" & sDate2 &"'"

This, of course, is the dynamic sql approach. You could just as easily pass sDate1 and sDate2 into a stored procedure.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Beginning Visual C# 2008
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date comparison problem mat41 Javascript 3 August 30th, 2006 09:22 PM
Date comparison rajuru Beginning PHP 2 February 19th, 2005 10:33 AM
Date comparison lily611 General .NET 5 January 4th, 2005 07:08 AM
Date Comparison hoffmann Classic ASP Databases 7 October 21st, 2004 09:00 AM
Date Comparison cmiller PHP How-To 3 June 19th, 2003 02:58 PM





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