473,394 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Unable to retrieve the date value from database

46
Hello Experts.

I am unable to retrieve records base on a date. Could you please help me.

Here is my code for user to insert a date :

Expand|Select|Wrap|Line Numbers
  1.  
  2. <form name="hello" method="post" action="querytable.asp">
  3. Please enter  date (mm/dd/yyyy)<input type="text" name="adate">
  4. <input type="submit" name="submit" value="submit">
  5. <form>
  6.  
  7.  
Here is my code for quering access database for the date

Expand|Select|Wrap|Line Numbers
  1.  
  2. <% @language="VBScript" %>
  3. <% option explicit %>
  4.  
  5. <%
  6. dim strDate
  7.  
  8. strDate = request.form("adate")
  9.  
  10.  
  11. dim adorst, adocon, strSQL, rst, sql
  12.  
  13. set adocon = server.createobject("ADODB.connection")
  14. adocon.open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " & server.mapPath("sp.mdb"))
  15.  
  16. set adorst = server.createobject("ADODB.recordset")
  17.  
  18. strSQL = "SELECT * from approval where datecreated = # " & strDate & " #" 
  19.  
  20.  
  21. adorst.open strSQL, adocon
  22.  
  23. %>
  24.  
  25.  
I get an error message Microsoft JET Database Engine (0x80040E07)
Syntax error in date in query expression 'datecreated = # #'.

When I use a constant date e.g
strSQL = "SELECT * from approval where datecreated = #01/01/2001#"
Then, the code works well. But I want to search the database on a date condition, i.e from the date the user has entered
Feb 25 '08 #1
5 1942
DrBunchman
979 Expert 512MB
Hi Giandeo,

It looks to me like your variable strDate is not getting a value assigned to it. Can you check whether this is the case by putting a

response.write("strDate: " & strDate)

in your code after you've assigned it (Use a constant date like you mentioned you have done before to stop it from erroring). If a date isn't displayed then something is wrong with the way the value is being assigned.

Hope this helps,

Dr b
Feb 25 '08 #2
CroCrew
564 Expert 512MB
Hello giandeo,

If the field “datecreated” in your database is a Date/Time field then…

If you’re looking for the records that fall ON the date passed in:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * from approval where datecreated = #" & strDate & "#"
If you’re looking for the records that fall BEFORE the date passed in:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * from approval where datecreated < #" & strDate & "#"
If you’re looking for the records that fall AFTER the date passed in:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * from approval where datecreated > #" & strDate & "#"
If you’re looking for the records that fall ON AND BEFORE the date passed in:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * from approval where datecreated =< #" & strDate & "#"
If you’re looking for the records that fall ON AND AFTER the date passed in:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * from approval where datecreated => #" & strDate & "#"
But like DrBunchman stated out if you’re not passing in a valid (date) value you’re going to have problems.

Hope that helps~
Feb 25 '08 #3
giandeo
46
Hello giandeo,

If the field “datecreated” in your database is a Date/Time field then…

If you’re looking for the records that fall ON the date passed in:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * from approval where datecreated = #" & strDate & "#"
If you’re looking for the records that fall BEFORE the date passed in:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * from approval where datecreated < #" & strDate & "#"
If you’re looking for the records that fall AFTER the date passed in:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * from approval where datecreated > #" & strDate & "#"
If you’re looking for the records that fall ON AND BEFORE the date passed in:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * from approval where datecreated =< #" & strDate & "#"
If you’re looking for the records that fall ON AND AFTER the date passed in:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * from approval where datecreated => #" & strDate & "#"
But like DrBunchman stated out if you’re not passing in a valid (date) value you’re going to have problems.

Hope that helps~
Hello Sir.

Your solutions are fantastic. I have been able to solve the problem. Thank you so much.

Actually, when I retrieve the data from the table I could see the date in the format mm/dd/yyyy

Sir, Is it possible to store date in access database in the British format:
e.g dd/mm/yyyyy

I am updating the database date/time field with the following code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. dim strdatecreated
  3.  
  4. strdatecreated = date()
  5.  
  6. adorst("datecreated") = strdatecreated
  7.  
  8.  
Feb 27 '08 #4
CroCrew
564 Expert 512MB
I am not an expert in Access but you can change the “Format” of your Date/Time filed to “Medium Date”. Medium Date falls more inline with Euro dates.
Feb 27 '08 #5
markrawlingson
346 Expert 100+
This should do the trick.

Expand|Select|Wrap|Line Numbers
  1. <%session.lcid=2057%>
  2.  
Here's a references online.

http://www.codetoad.com/asp/format_date_time.asp

Scroll down on the page, it will show you all the LCIDs (Local IDs) for all the international locales - as the website says, be aware that these will also change your currency formatting.

[edit]
I should also mention that this won't store the date in dd/mm/yyyy format in your database but will rather use ASP to translate any date into dd/mm/yyyy format - So you store it in your db as mm/dd/yyyy and once it's spat onto the page it should appear dd/mm/yyyy instead because of the locale id.

Sincerely,
Mark
Feb 27 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Daniel Tonks | last post by:
First, please excuse the fact that I'm a complete MySQL newbie. My site used forum software that I wrote myself (in Perl) which, up until now, has used flat files. This worked fine, however...
2
by: Uthuras | last post by:
Greetings all, Machine : PENTIUM Os :Windows 2000 Product : DB2 UDB EE Release : 7.2 I've extracted data from a RDBMS database and try to load into DB2 database. I extracted the...
2
by: Rob | last post by:
Hi all, I've got multiple sets of radio button that are dynamically created in code and populated by a database query. The query returns about 20 recordsets with 3 radio buttons per recordset and...
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
2
by: michele | last post by:
Hi, I want to load a listbox with the date that are stored in a database (mdb), the problem is when I retrieve the date it has a format like "01/01/2006 0.00.00". In Access the date is stored as...
4
by: Simon Gare | last post by:
Hi all, I am trying to retrieve a count of booking entries made 30 days ago, below is the end of the query I am having problems with. dbo.booking_form.TimeOfBooking = DATEADD(day, -30,...
2
by: Josh T | last post by:
As of now I am setting a cookie on my aspx page via javascript, function SetCookie(cookieName, value, minutesToExpire) { ClearCookie(cookieName); var expireDate = new Date(); var...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
1
by: divya | last post by:
Hello, I used the below code to move selected items between two listboxes Left and Right:- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPopup.aspx.cs" Inherits="TestPopup" %> ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.