473,406 Members | 2,439 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,406 software developers and data experts.

Date format in SQl to compare field with system date

I have a problem I just can't get any sort of query findfirst or the sql below to correctly compare a value in a table with a supplied value.

I created a very simple situation to try and figure part of it out. I have one table with three fields ID, myname and Birthday. There are three records in there one has a birthday of 01/04/2008 (todays date - this is NOT an April Fool!) The Birthday field is formated as a date and just takes the system date format which is dd/mm/yyyy.

I am trying to get this code (below) to realise that a birthday with todays date does exist. However I keep getting the message "no birthdays match the system date". If I do a less than comparison it finds some dates.


Thanks for any help.

Lou
Expand|Select|Wrap|Line Numbers
  1. Dim db As Database
  2.     Set db = CurrentDb
  3.     Dim rec As DAO.Recordset
  4.     Dim strSQL As String
  5.  
  6.     strSQL = "SELECT Top 1 * FROM table1 " _
  7.     & "WHERE [Birthday] = #" & Date & "# " _
  8.     & "ORDER BY [Birthday]"
  9.  
  10.     Set rec = db.OpenRecordset(strSQL)
  11.  
  12.     If rec.EOF Then
  13.     MsgBox "no birthdays match the system date"
  14.     Else
  15.     MsgBox "birthdays match the system date"
  16.     End If
Apr 1 '08 #1
2 2724
This is the solution
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT Top 1 * FROM table1 " _
  2.        & "WHERE [Birthday] = Date()" _
  3.        & "ORDER BY [Birthday]"
OR
Expand|Select|Wrap|Line Numbers
  1. Dim todaysdate As String
  2.     todaysdate = Date
  3.  
  4.     strSQL = "SELECT Top 1 * FROM table1 " _
  5.        & "WHERE [Birthday] = #" & Format(todaysdate, "mm\/dd\/yyyy") & "#"
  6.        & "ORDER BY [Birthday]"
Lou
Apr 1 '08 #2
NeoPa
32,556 Expert Mod 16PB
It seems like you've come across the SQL Date Literal issue. See Literal DateTimes and Their Delimiters (#) for a fuller explanation.
Apr 2 '08 #3

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

Similar topics

4
by: peashoe | last post by:
I have an asp page that uses a calendar.js (pop-up) file to add an exact date format in the text field (txtDDate). My problem is I need some javascript that sets an alert that does not allow them...
1
by: Flipmode | last post by:
I am fairly novice at VB and access in particular and I am having problems trying store a date into database field. This is the scenario I am faced with. I want to when click on a pause button...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
9
by: Shapper | last post by:
Hello, I created a dataset from a XML file. One of the dataset fields is . In an ASP:Repeater I am displaying the field. <%# DataBinder.Eval(Container.DataItem, "pubDate", "{0:f}") %> The...
8
by: John Wildes | last post by:
Hello all I'm going to try and be brief with my question, please tell me if I have the wrong group. We are querying transaction data from a DB3 database application. The dates are stored as...
3
by: Peter | last post by:
ASP.NET 1.1, this is a Intranet application and runs only on IE. I have two webform text boxes which contain dates - starting date and ending date. The dates could be in any format. for...
4
by: blini | last post by:
Helo.... How I can convert string "26/03/2006 15:51" for a date? I need to convert and to compare if "09/06/2006 14:20" is lesser or equal that the current date. Everything in Javascript.
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
2
by: sparks | last post by:
I am trying to find valid records in a table but I must compare a date field to a date stored in the table I can see where this is wrong (ok I guess its not text) "= """ & Me.date & """" so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.