I'm trying to calculate, from a SQL statement, the count of days to a persons birthday.
I'm trying the following:
strSQL = "SELECT * FROM Employees WHERE (DateDiff('d', Date, (DateSerial(Month([DateOfBirth]),Day([DateOfBirth]),Year(Date))) BETWEEN 0 AND 5"
The [DateOfBirth] is a field in the Employees table. Yet, I always receive a 3061 runtime error... anybody got any idea what is wrong? Yes, there are records in the table satisfying the asked conditions.
Many many thanks in advance!
8 8691
Hello,
well I don't know the answer but I always make a Query in DesignView in MSAccess and when it executes okay then I look at the SQL syntax that this query is using by selecting the 'SQL-view' option in this designview query.
regards,
Henk
I'm trying to calculate, from a SQL statement, the count of days to a persons birthday.
I'm trying the following:
strSQL = "SELECT * FROM Employees WHERE (DateDiff('d', Date, (DateSerial(Month([DateOfBirth]),Day([DateOfBirth]),Year(Date))) BETWEEN 0 AND 5"
The [DateOfBirth] is a field in the Employees table. Yet, I always receive a 3061 runtime error... anybody got any idea what is wrong? Yes, there are records in the table satisfying the asked conditions.
Many many thanks in advance!
The datediff function uses 3 values separated by commas, you have more then that by the way you have the last date values entered. My guess is, that is what is throwing your error.
Why not just use "WHERE DateDiff("d",Format(DateOfBirth, "mmddyyyy"), Date) Between 0 and 5
The datediff function uses 3 values separated by commas, you have more then that by the way you have the last date values entered. My guess is, that is what is throwing your error.
Why not just use "WHERE DateDiff("d",Format(DateOfBirth, "mmddyyyy"), Date) Between 0 and 5
Thanks, I'm still tinkering with this though..
I'm currently trying -
SQL = "SELECT * FROM Employees WHERE DateDiff('d', Format([DoB], 'General Date'), Format(Date, 'General Date') ) BETWEEN 0 AND 5;"
-
Set rs = db.OpenRecordset(SQL, dbOpenDynaset)
-
But that keeps reporting a (Excpected: 1) runtime error. Any clues?
Thanks, I'm still tinkering with this though..
I'm currently trying -
SQL = "SELECT * FROM Employees WHERE DateDiff('d', Format([DoB], 'General Date'), Format(Date, 'General Date') ) BETWEEN 0 AND 5;"
-
Set rs = db.OpenRecordset(SQL, dbOpenDynaset)
-
But that keeps reporting a (Excpected: 1) runtime error. Any clues?
My guess is you're trying to find the employees with a birthday in the next five days... Try this: - SELECT * FROM Employees WHERE DateDiff('d', Format(now(), 'General Date'), Format([DoB], 'General Date') ) BETWEEN 0 AND 5;
This worked for me :)
Patrick Cullen, ZA
My guess is you're trying to find the employees with a birthday in the next five days... Try this: - SELECT * FROM Employees WHERE DateDiff('d', Format(now(), 'General Date'), Format([DoB], 'General Date') ) BETWEEN 0 AND 5;
This worked for me :)
Patrick Cullen, ZA
Am I missing something obvious here? Surely this would return the number of days between the date they were born and now. i.e. more than 7,000 days. Unless, of course, you are looking for 5 day old employees :)
Thanks, I'm still tinkering with this though..
I'm currently trying -
SQL = "SELECT * FROM Employees WHERE DateDiff('d', Format([DoB], 'General Date'), Format(Date, 'General Date') ) BETWEEN 0 AND 5;"
-
Set rs = db.OpenRecordset(SQL, dbOpenDynaset)
-
But that keeps reporting a (Excpected: 1) runtime error. Any clues?
This gives me 4 -
DateOfBirth = #11/11/2006#
-
MsgBox DateDiff("d", Now, DateSerial(Year(Date), Month(DateOfBirth), Day(DateOfBirth)))
-
It seems that you may have entered the DateSerial parameters in the wrong order.
This gives me 4 -
DateOfBirth = #11/11/2006#
-
MsgBox DateDiff("d", Now, DateSerial(Year(Date), Month(DateOfBirth), Day(DateOfBirth)))
-
It seems that you may have entered the DateSerial parameters in the wrong order.
Whatever I try, I can't get it to work.
For example, I try:
[code
SQL = "SELECT * FROM Werknemers WHERE DateDiff('d', Format(DateSerial(Year(Now),Month(Geboortedatum),D ay(GeboorteDatum)), 'Short Date'), Format(Date, 'Short Date') ) BETWEEN 0 AND 5;"
[/code]
This keeps on giving error 3601... while I can't find any problem.. any clues?
try this -
-
SQL = "SELECT * FROM Werknemers WHERE month(now) = month(DateOfBirth) and day(DateOfBirth) - day(now) > -1 and day(DateOfBirth) - day(now) < 6
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Frnak McKenney |
last post by:
Back when computer dinosaurs roamed the earth and the precursors to
today's Internet were tiny flocks of TDMs living symbiotically with
the silicon giants, tracking access to data processing...
|
by: Joris Kempen |
last post by:
Hi people,
I know that the question has come around sometimes:
How to open an Access Report using ASP and export it to for example
RTF.
I'm trying to implement the first method of David...
|
by: Sean C. |
last post by:
Helpful folks,
Most of my previous experience with DB2 was on s390 mainframe systems
and the optimizer on this platform always seemed very predictable and
consistent. Since moving to a WinNT/UDB...
|
by: bhbgroup |
last post by:
I have a query on one large table. I only add one condition, i.e. a
date (the SQL reads like 'where date > parameterdate'.
This query is rather quick if 'parameterdate' is either explicitly...
|
by: Neil |
last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is
upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server
at the same time. We're moving to SQL Server...
|
by: tt40 |
last post by:
Anyone know how to prevent Access 2002 from automatically breaking all
the incorrect joins in a query and then automatically saving the broken
query?
This is what I would call stupid design...
|
by: InnoCreate |
last post by:
Hi everyone.
I've recently written a classic asp website which uses an MS Access
datasource. I know this is less than an ideal data source as it has
limited functionality. I have a search form on...
|
by: mnjkahn via AccessMonster.com |
last post by:
I'm running Access 2003, modifying a query that has over 45 fields. When I
right click on the field name in Query Design View, and then click Build,
Access crashes before the Build window...
|
by: jsacrey |
last post by:
Hey everybody, got a secnario for ya that I need a bit of help with.
Access 97 using linked tables from an SQL Server 2000 machine.
I've created a simple query using two tables joined by one...
|
by: magickarle |
last post by:
Hi, I got a pass-through query (that takes about 15 mins to process)
I would like to integrate variables to it.
IE: something simple:
Select EmplID from empl_Lst
where empl_lst.timestamp between...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |