Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 4th, 2005, 12:42 PM
Authorized User
 
Join Date: Jun 2003
Location: Gulfport, Ms, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default Formatting For Between Dates

I'm working with a database that has dates broken up when stored. I.E.: month, day, and year are each stored in a seperate column. My problem is that I need to query between date ranges and I'm unsure of how to proceed. The plan is to have the user input through a form and then format the input into a date to use for query.

Is it possible to preformat the recordset query such as:

Dim fromdate, todate
fromdate = FormatDateTime(Request(fmonth) & "/" & Request(fday)
           & "/" & Request(fyear), 2)
todate = FormatDateTime(Request(tmonth) & "/" & Request(tday)
           & "/" & Request(tyear), 2)

Select * FROM DB WHERE FormatDateTime(column1date "/" column2date "/"
       column3date, 2) BETWEEN " & fdate & " AND " & tdate

Thanks for any help!
Reply With Quote
  #2 (permalink)  
Old February 4th, 2005, 01:23 PM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

You can use Convert function in SQL

CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

Om Prakash
Reply With Quote
  #3 (permalink)  
Old February 4th, 2005, 01:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,111
Thanks: 0
Thanked 3 Times in 3 Posts
Default

It might be easier, if you can, to not separate them when you store them. There are plenty of functions to manipulate dates to pull back just the month, day, etc.

This might not work because you need one column where the formatdatetime is.
Select * FROM DB WHERE FormatDateTime(column1date "/" column2date "/"
       column3date, 2) BETWEEN " & fdate & " AND " & tdate

You will probably have to take apart the input date(s) and select based on month, year, and day.
http://www.devx.com/tips/Tip/5524

select * from db where columnyear between '" & szYear & "'
                   and columnmonth between '" & szMonth ... etc
(variables from the link)



Reply With Quote
  #4 (permalink)  
Old February 4th, 2005, 01:57 PM
Authorized User
 
Join Date: Jun 2003
Location: Gulfport, Ms, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default

I wish the dates could be stored complete. That would definitely make my life ALOT easier. I knew I would have to do some sort of breakdown but I was hoping I was making a bigger deal out of it than it needed to be.

Thanks for the responses!
Reply With Quote
  #5 (permalink)  
Old February 4th, 2005, 09:14 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Is there any special reason they need to be stored like that? (appart from having to alter any insert/update etc statements) If not, I would:
1..Create a new field
2..Write a script to get each of the three date parts from each row
3..Concantenate them
4..Insert them into your newly created field as a date data type
5..Then alter the pages that address these wierdly stored date parts

Wind is your friend
Matt
Reply With Quote
  #6 (permalink)  
Old February 7th, 2005, 03:15 PM
Authorized User
 
Join Date: Jun 2003
Location: Gulfport, Ms, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default

Matt,
Everything is read only so I cannot add a new field to the DB.
Reply With Quote
  #7 (permalink)  
Old February 7th, 2005, 05:09 PM
Authorized User
 
Join Date: Jun 2003
Location: Gulfport, Ms, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default

I do have another question.

I created an Access database and used the BETWEEN operator to query between dates as it should be. Example:

Dim fdate, tdate
fdate = Request.Form("fmonth") & "/" & Request.Form("fday") & "/" & Request.Form("fyear")
tdate = Request.Form("tmonth") & "/" & Request.Form("tday") & "/" & Request.Form("tyear")

"SELECT * FROM dates WHERE date BETWEEN '" & fdate & "' AND '" & _
        tdate & "' ORDER BY date"

It will display all dates as it should if the fmonth and tmonth are less than 10 (1-9) or if the fmonth and tmonth are 10-12. If I query dates where the fmonth is single digit and the tmonth are double digit the I only get results based on the double digit month.

Any idea what may be causing this? Leading zero maybe?
Reply With Quote
  #8 (permalink)  
Old February 8th, 2005, 02:29 AM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

mmmmm your using access without the # round the dates and its working?

;;;Leading zero maybe?
No I dont believe so

Response.write your sql and copy n paste it here from the bowser

Also I would cDate your date values:
cDate Function:
"Returns an expression that has been converted to a Variant of subtype Date"
Eg cDate(fDate) and cDate(tdate)

Wind is your friend
Matt
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Dates dhoward SQL Language 4 January 30th, 2007 04:00 PM
formatting strings / dates clandestine XML 3 June 22nd, 2005 09:52 AM
formatting dates treasacrowe Classic ASP Basics 3 October 20th, 2004 06:52 PM
Formatting dates in XSL francislang XSLT 4 September 3rd, 2004 08:17 AM
Formatting Dates Louisa VB.NET 2002/2003 Basics 3 March 16th, 2004 05:52 AM



All times are GMT -4. The time now is 02:31 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.