SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 22nd, 2004, 12:34 PM
nparthi nparthi is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 21 nparthi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 31 sec
Reputation Power: 0
Date query using Calendar Control in ASP.NET

strSQL = "SELECT * " & _
" FROM Tracker2 " & _
" WHERE Start_date >= '" & BeginDate.SelectedDate & "' AND Ticket_type='" & ddlTicketType.SelectedValue() & "' ORDER By Start_date"

This query works to retrieve all records 'from' the date I choose in my calendar control. I would like to display for ONLY the date I choose on my calendar control, but when I change my query to

" WHERE Start_date = '" & BeginDate.SelectedDate & "'

it doesn't diaplay anything?? Why?

Reply With Quote
  #2  
Old January 22nd, 2004, 02:07 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
There may be an issue with your database field. what data type are you using in the database??? DateTime or SmallDateTime? how is it storing the values??? If it is storing the date and time in the database and you are only passing a date from the calendar, then you won't get any records returned, because the time isn't being passed.

If the database has this
01-22-2003 2:11:41 PM

And you are passing this from you calendar
01-22-2003

There won't be any records returned, because every record in the database has a time associated with it.

Reply With Quote
  #3  
Old January 22nd, 2004, 03:28 PM
nparthi nparthi is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 21 nparthi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 31 sec
Reputation Power: 0
I have it as datatime on my SQL server like this 01-22-2003 2:11:41 PM.

But a range of date query works :

strSQL = "SELECT *" & _
" FROM Tracker2 " & _
" WHERE Start_date >= '" & BeginDate.SelectedDate & "' AND Start_date <= '" & EndDate.SelectedDate & "' AND Ticket_type='" & ddlTicketType.SelectedValue() & "' ORDER By Start_date"

where BeginDate and EndDate are 2 calendar controls.

I would like to use only 1 Calendar control and want to change the WHERE part of the query to " WHERE Start_date = '" & BeginDate.SelectedDate & "' -- so that I can see the records entered for 1 day at a time

Also, when I enter the EndDate to be 'today's date' it displays only the records till yesterday...it DOES NOT show the records added today??? Is it bcos of the datetime format..if so how do I rectify it??

Last edited by nparthi : January 22nd, 2004 at 03:41 PM.

Reply With Quote
  #4  
Old January 22nd, 2004, 06:02 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
The reason the date range works is because when you select the start date in the calendar (01-22-2003) and the end date (01-23-2003) and pass it to the database, it is appending the time onto it like this (start date = 01-22-2003 00:00:00 AM...end date = 01-23-2003 00:00:00 AM). Therefore it will return rows where the start date is greater 0r equal to 01-22-2003 00:00:00 AM and the end date is less than or equal to 01-23-2003 00:00:00 AM.

but unless you have a row with the start date = 01-22-2003 00:00:00 AM, it won't find a record.

If you just pass in a date, it will default the time to midnight

so passing in 01-22-2003 and 01-23-2003 will only return records that were entered in between midnight on 01-22 and midnight on 01-23 (a 24 hour period)

the best way to do it would be to not have the time on in the date...change the datatype to smalldatetime and pass your dates without the time like this
Code:
Cast(Convert(varchar(20),GetDate(),101) as SmallDateTime)


or change the data type of the date fields to varchar(10) or text 10 (Access)...The time part is what is causing the problem when you are searching for records that equal a specific date.

Reply With Quote
  #5  
Old February 6th, 2004, 11:13 AM
nparthi nparthi is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 21 nparthi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 31 sec
Reputation Power: 0
<del>

Last edited by nparthi : February 6th, 2004 at 11:25 AM.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Date query using Calendar Control in ASP.NET


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT