473,771 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date format in SQl to compare field with system date

3 New Member
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 2745
Louverril
3 New Member
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,573 Recognized Expert Moderator MVP
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
3452
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 to select today. example: var dtToday = Date() if(document.frmSoftware.txtDDate.value == dtToday) { alert("You cannot select same day distributions. Please enter a new
1
1794
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 and store the current date time in a pause time field then when it is then unclicked it is to add the time that elapsed to a total pause time field and the reset the pause time back to Null.
7
31841
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 current date. If not, I'd like to display the error message to ValidationSummary. It seems to make sense to me to use CompareValidator but the problem is put the current date into CompareValidator. So, I created a hidden text field in my aspx. ...
9
1976
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 date displayed has the following format, the same as in the XML file:
8
3655
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 text fields. Each date for example 10/31/03 or October 31st 2003 is stored as 10/31/A3 in the system. My reasoning for this is because they couldn't solve their Y2K problem or this is their solution to it. All dates prior to 2000 are stored...
3
2591
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 example: Starting date: 02/15/2006 Ending date: March 2006 I have to make sure the starting date is before the ending date
4
3765
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
29469
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 follows: function doDateCheckNow(source, args) { var oDate = document.getElementById(source.controltovalidate); // dd/mm/yyyy
2
3042
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 how do you format for a date comparison of a date field in a table and compared to a text box with a date format?
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.