?
Solved

Get Birthday

Posted on 2002-04-03
11
Medium Priority
?
358 Views
Last Modified: 2010-05-02
Hi Expert,

I would like like write a function to get Staff Birthday whose birthday within -7<=NOW<=7

I face difficult when the birthday at the year end and how can i compare it correctly?

I use Access as my database to store the data,

please help

Thanks
kchoed
0
Comment
Question by:kchoed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6917174
"Select * from Staff Where BirthDay between Date - 7 And Date + 7" ?
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6917178
or

"Select * from Staff Where BirthDay between " dateadd("d",-7,date) & " And " & dateadd("d",7,date)
0
 

Author Comment

by:kchoed
ID: 6917189
Hi,

I just need to compare the Day and Month, no need to compare YEAR, so how can i do it ?

Thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:riaz9
ID: 6917314
Hi kchoed, this should work - here i am substituting the year of the DOB with the current year, so you will get the result you want. You can execute this query from vb and get your result.

SELECT Name, DOB  from Applications where
Month(DOB) & '/' & Day(DOB) & '/' & Year(Date()) >= DateAdd("d",-7,Date())
and Month(DOB) & '/' & Day(DOB) & '/' & Year(Date()) <= DateAdd("d",7,Date())
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6917322
SQL = "Select * from Staff Where BirthDay between " dateadd("d",-7,date) & " And " & dateadd("d",7,date) & " And Year(BirthDay) = Year(Date)" ?
0
 

Author Comment

by:kchoed
ID: 6917389
Hi ALL,

Thanks for your propsed answer first, but I have face the problem , when today is 01/01/2002, I can't compare one birthday with 26/12

Any suggestion?

Thanks
kchoed
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6917391
Sorry, try this:

SQL = "Select * from Staff Where BirthDay between #" Format$(dateadd("d",-7,date),"mm/dd/yyyy") & "# And #" & Format$(dateadd("d",7,date),"mm/dd/yyyy") & "#"

or what exact you want ..?
0
 

Author Comment

by:kchoed
ID: 6917412
Hi ryancys

I just want to compare the Month and Day with Today, but when today like "01/01", it can't compare the Staff Birthday with date like 26/12

Thanks for suggestion
kchoed
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6917495
If Current Year = 2002

Is '26/12' belong to 2001 ?

What is the Data Type of 'Birthday'? A Date?

Please give an example of 'Birthday' value in database.

regards

0
 
LVL 2

Accepted Solution

by:
skhorshid earned 400 total points
ID: 6917607
This will work if you have a table call staff and a dob date/time field,  I have tested this in access 2000

The date from parameter is mm

Basically it gets the day and month from the dob field adds it to the this year, the year before and the next year and calculates if the new date/s are within 7 days of mm,  the input date parateter

SELECT DISTINCT staff.*
FROM staff
WHERE (((Abs(DateDiff("d",DateAdd("d",Day([staff].[dob]),DateAdd("m",Month([staff].[dob])-1,DateAdd("yyyy",Year(Now())-1900,"31/12/1899"))),[mm])))<=7))
or
 (((Abs(DateDiff("d",DateAdd("d",Day([staff].[dob]),DateAdd("m",Month([staff].[dob])-1,DateAdd("yyyy",Year(Now())-1901,"31/12/1899"))),[mm])))<=7))
or
(((Abs(DateDiff("d",DateAdd("d",Day([staff].[dob]),DateAdd("m",Month([staff].[dob])-1,DateAdd("yyyy",Year(Now())-1899,"31/12/1899"))),[mm])))<=7));
0
 

Author Comment

by:kchoed
ID: 6922416
hi skhorshid

Thanks a lot , it is very useful for me

kchoed
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question