Find anniversary of a date

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table with birthdate of persons
I would like to write a query giving me all anniveraries coming up within
one month from now.
Can someone help me with this?
 
In your query, enter the following criteria in your birthdate column
between date() and date()+31 This will give you the dates for the next 31
days.
 
thanks for your reply, but that does not seem to work....
it gives me only dates that are between date() and date()+31 not
anniversaries of dates (by the way...some months have 28,30 days not 31)
so any other suggestions?
 
i tried:
WHERE DateSerial(Year(now()),Month([birthday]),Day([birthday])) BETWEEN
now() AND DateAdd("m",1,now())

but that gave me an error of incompatible types and
it will not work for birthday 10 january 1950 when it is now 15 december 2005

so what to do??? can anyone help?
 
Assuming [birthday] is a date field (as opposed to a text field), that
should work.

One thing that could be causing a problem is if you've created any objects
(variables, controls on forms, fields in tables, etc.) named Year, Month or
Day.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Rli said:
i tried:
WHERE DateSerial(Year(now()),Month([birthday]),Day([birthday])) BETWEEN
now() AND DateAdd("m",1,now())

but that gave me an error of incompatible types and
it will not work for birthday 10 january 1950 when it is now 15 december
2005

so what to do??? can anyone help?

Rli said:
thanks for your reply, but that does not seem to work....
it gives me only dates that are between date() and date()+31 not
anniversaries of dates (by the way...some months have 28,30 days not 31)
so any other suggestions?
 
Yes, thought it should, but it does give an error: for instance

SELECT people.birthdate,
DateAdd("yyyy",Year(Now())-Year(people.birthdate)+1,people.birthdate) AS
birthday
FROM people
WHERE DateAdd("yyyy",Year(Now())-Year(people.birthdate)+1,people.birthdate)
Between now() And DateAdd("m",1,NOW());


gives the error (sorry, in french...) "Type de données incompatible dans
l'expression du critère" (in short...incompatible types in the criteria,
Error 3464)
OR no records at all......

When i remove the WHERE part it works fine and gives birthday for all records.

But as soon as i use "Dateadd.... between .. and.." as a criteria it fails
for incompatible types
[Birthdate] is a date field....and i did not create any of the objects you
mention.

can you see why?
But still even if this does work, it would not give me all the brithdays for
next month...

So the initial question how to retrieve birthdays still stands....

Douglas J. Steele said:
Assuming [birthday] is a date field (as opposed to a text field), that
should work.

One thing that could be causing a problem is if you've created any objects
(variables, controls on forms, fields in tables, etc.) named Year, Month or
Day.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Rli said:
i tried:
WHERE DateSerial(Year(now()),Month([birthday]),Day([birthday])) BETWEEN
now() AND DateAdd("m",1,now())

but that gave me an error of incompatible types and
it will not work for birthday 10 january 1950 when it is now 15 december
2005

so what to do??? can anyone help?

Rli said:
thanks for your reply, but that does not seem to work....
it gives me only dates that are between date() and date()+31 not
anniversaries of dates (by the way...some months have 28,30 days not 31)
so any other suggestions?

:

In your query, enter the following criteria in your birthdate column
between date() and date()+31 This will give you the dates for the next
31
days.

--
Allan Murphy
Email: (e-mail address removed)
I have a table with birthdate of persons
I would like to write a query giving me all anniveraries coming up
within
one month from now.
Can someone help me with this?
 
Do you have any rows in your table where birthdate is null?

I just ran the exact query as a test, and I got the same error message as
you for Null dates. Adding "AND People.Birthdate IS NOT NULL" solved it for
me...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Rli said:
Yes, thought it should, but it does give an error: for instance

SELECT people.birthdate,
DateAdd("yyyy",Year(Now())-Year(people.birthdate)+1,people.birthdate) AS
birthday
FROM people
WHERE
DateAdd("yyyy",Year(Now())-Year(people.birthdate)+1,people.birthdate)
Between now() And DateAdd("m",1,NOW());


gives the error (sorry, in french...) "Type de données incompatible dans
l'expression du critère" (in short...incompatible types in the criteria,
Error 3464)
OR no records at all......

When i remove the WHERE part it works fine and gives birthday for all
records.

But as soon as i use "Dateadd.... between .. and.." as a criteria it fails
for incompatible types
[Birthdate] is a date field....and i did not create any of the objects you
mention.

can you see why?
But still even if this does work, it would not give me all the brithdays
for
next month...

So the initial question how to retrieve birthdays still stands....

Douglas J. Steele said:
Assuming [birthday] is a date field (as opposed to a text field), that
should work.

One thing that could be causing a problem is if you've created any
objects
(variables, controls on forms, fields in tables, etc.) named Year, Month
or
Day.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Rli said:
i tried:
WHERE DateSerial(Year(now()),Month([birthday]),Day([birthday])) BETWEEN
now() AND DateAdd("m",1,now())

but that gave me an error of incompatible types and
it will not work for birthday 10 january 1950 when it is now 15
december
2005

so what to do??? can anyone help?

:

thanks for your reply, but that does not seem to work....
it gives me only dates that are between date() and date()+31 not
anniversaries of dates (by the way...some months have 28,30 days not
31)
so any other suggestions?

:

In your query, enter the following criteria in your birthdate column
between date() and date()+31 This will give you the dates for the
next
31
days.

--
Allan Murphy
Email: (e-mail address removed)
I have a table with birthdate of persons
I would like to write a query giving me all anniveraries coming up
within
one month from now.
Can someone help me with this?
 
Yes....that helps...it actually does not give the error anymore

But it does not give me the right birthdays coming for the next month


Douglas J. Steele said:
Do you have any rows in your table where birthdate is null?

I just ran the exact query as a test, and I got the same error message as
you for Null dates. Adding "AND People.Birthdate IS NOT NULL" solved it for
me...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Rli said:
Yes, thought it should, but it does give an error: for instance

SELECT people.birthdate,
DateAdd("yyyy",Year(Now())-Year(people.birthdate)+1,people.birthdate) AS
birthday
FROM people
WHERE
DateAdd("yyyy",Year(Now())-Year(people.birthdate)+1,people.birthdate)
Between now() And DateAdd("m",1,NOW());


gives the error (sorry, in french...) "Type de données incompatible dans
l'expression du critère" (in short...incompatible types in the criteria,
Error 3464)
OR no records at all......

When i remove the WHERE part it works fine and gives birthday for all
records.

But as soon as i use "Dateadd.... between .. and.." as a criteria it fails
for incompatible types
[Birthdate] is a date field....and i did not create any of the objects you
mention.

can you see why?
But still even if this does work, it would not give me all the brithdays
for
next month...

So the initial question how to retrieve birthdays still stands....

Douglas J. Steele said:
Assuming [birthday] is a date field (as opposed to a text field), that
should work.

One thing that could be causing a problem is if you've created any
objects
(variables, controls on forms, fields in tables, etc.) named Year, Month
or
Day.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



i tried:
WHERE DateSerial(Year(now()),Month([birthday]),Day([birthday])) BETWEEN
now() AND DateAdd("m",1,now())

but that gave me an error of incompatible types and
it will not work for birthday 10 january 1950 when it is now 15
december
2005

so what to do??? can anyone help?

:

thanks for your reply, but that does not seem to work....
it gives me only dates that are between date() and date()+31 not
anniversaries of dates (by the way...some months have 28,30 days not
31)
so any other suggestions?

:

In your query, enter the following criteria in your birthdate column
between date() and date()+31 This will give you the dates for the
next
31
days.

--
Allan Murphy
Email: (e-mail address removed)
I have a table with birthdate of persons
I would like to write a query giving me all anniveraries coming up
within
one month from now.
Can someone help me with this?
 
Sorry to jump in here, but I've been watching the thread for a bit out of
interest and have found that this works:


SELECT People.Birthdate,
DateAdd("yyyy",Year(Date())-Year([People].[Birthdate]),[People].[Birthdate])
AS Birthday
FROM People WHERE (((People.Birthdate) Is Not Null) AND
((DateAdd("yyyy",Year(Date())-Year([People].[Birthdate]),[People].[Birthdate
])) Between Date() And DateAdd("m",1,Date())));

HTH

Debra

Rli said:
Yes....that helps...it actually does not give the error anymore

But it does not give me the right birthdays coming for the next month


Douglas J. Steele said:
Do you have any rows in your table where birthdate is null?

I just ran the exact query as a test, and I got the same error message as
you for Null dates. Adding "AND People.Birthdate IS NOT NULL" solved it for
me...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Rli said:
Yes, thought it should, but it does give an error: for instance

SELECT people.birthdate,
DateAdd("yyyy",Year(Now())-Year(people.birthdate)+1,people.birthdate) AS
birthday
FROM people
WHERE
DateAdd("yyyy",Year(Now())-Year(people.birthdate)+1,people.birthdate)
Between now() And DateAdd("m",1,NOW());


gives the error (sorry, in french...) "Type de données incompatible dans
l'expression du critère" (in short...incompatible types in the criteria,
Error 3464)
OR no records at all......

When i remove the WHERE part it works fine and gives birthday for all
records.

But as soon as i use "Dateadd.... between .. and.." as a criteria it fails
for incompatible types
[Birthdate] is a date field....and i did not create any of the objects you
mention.

can you see why?
But still even if this does work, it would not give me all the brithdays
for
next month...

So the initial question how to retrieve birthdays still stands....

:

Assuming [birthday] is a date field (as opposed to a text field), that
should work.

One thing that could be causing a problem is if you've created any
objects
(variables, controls on forms, fields in tables, etc.) named Year, Month
or
Day.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



i tried:
WHERE DateSerial(Year(now()),Month([birthday]),Day([birthday])) BETWEEN
now() AND DateAdd("m",1,now())

but that gave me an error of incompatible types and
it will not work for birthday 10 january 1950 when it is now 15
december
2005

so what to do??? can anyone help?

:

thanks for your reply, but that does not seem to work....
it gives me only dates that are between date() and date()+31 not
anniversaries of dates (by the way...some months have 28,30 days not
31)
so any other suggestions?

:

In your query, enter the following criteria in your birthdate column
between date() and date()+31 This will give you the dates for the
next
31
days.

--
Allan Murphy
Email: (e-mail address removed)
I have a table with birthdate of persons
I would like to write a query giving me all anniveraries coming up
within
one month from now.
Can someone help me with this?
 
Hi Debra, thank you for 'jumping in'.

But does your query give the birthday 15/01/2006 on systemdate 16 december
2005 when someone was born on 15/01/1960 ???
I dont think so because it will test on birthday 15/01/2005 and not 15/01/2006

you see what i mean?

Debra Farnham said:
Sorry to jump in here, but I've been watching the thread for a bit out of
interest and have found that this works:


SELECT People.Birthdate,
DateAdd("yyyy",Year(Date())-Year([People].[Birthdate]),[People].[Birthdate])
AS Birthday
FROM People WHERE (((People.Birthdate) Is Not Null) AND
((DateAdd("yyyy",Year(Date())-Year([People].[Birthdate]),[People].[Birthdate
])) Between Date() And DateAdd("m",1,Date())));

HTH

Debra

Rli said:
Yes....that helps...it actually does not give the error anymore

But it does not give me the right birthdays coming for the next month


Douglas J. Steele said:
Do you have any rows in your table where birthdate is null?

I just ran the exact query as a test, and I got the same error message as
you for Null dates. Adding "AND People.Birthdate IS NOT NULL" solved it for
me...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Yes, thought it should, but it does give an error: for instance

SELECT people.birthdate,
DateAdd("yyyy",Year(Now())-Year(people.birthdate)+1,people.birthdate) AS
birthday
FROM people
WHERE
DateAdd("yyyy",Year(Now())-Year(people.birthdate)+1,people.birthdate)
Between now() And DateAdd("m",1,NOW());


gives the error (sorry, in french...) "Type de données incompatible dans
l'expression du critère" (in short...incompatible types in the criteria,
Error 3464)
OR no records at all......

When i remove the WHERE part it works fine and gives birthday for all
records.

But as soon as i use "Dateadd.... between .. and.." as a criteria it fails
for incompatible types
[Birthdate] is a date field....and i did not create any of the objects you
mention.

can you see why?
But still even if this does work, it would not give me all the brithdays
for
next month...

So the initial question how to retrieve birthdays still stands....

:

Assuming [birthday] is a date field (as opposed to a text field), that
should work.

One thing that could be causing a problem is if you've created any
objects
(variables, controls on forms, fields in tables, etc.) named Year, Month
or
Day.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



i tried:
WHERE DateSerial(Year(now()),Month([birthday]),Day([birthday])) BETWEEN
now() AND DateAdd("m",1,now())

but that gave me an error of incompatible types and
it will not work for birthday 10 january 1950 when it is now 15
december
2005

so what to do??? can anyone help?

:

thanks for your reply, but that does not seem to work....
it gives me only dates that are between date() and date()+31 not
anniversaries of dates (by the way...some months have 28,30 days not
31)
so any other suggestions?

:

In your query, enter the following criteria in your birthdate column
between date() and date()+31 This will give you the dates for the
next
31
days.

--
Allan Murphy
Email: (e-mail address removed)
I have a table with birthdate of persons
I would like to write a query giving me all anniveraries coming up
within
one month from now.
Can someone help me with this?
 
Wow, this is getting enormous...
it seemed such a simple problem at first...
but it WORKS....

thank you, still don't understand yet how it works...but i will find out
Thank you.....
(i did correct the spelling of brithday to birthday first...)

Debra Farnham said:
Think I got it

Try this:

SELECT People.Brithdate,
IIf(DateAdd("yyyy",Year(Date())-Year([People].[Brithdate]),[People].[Brithda
te])<=Date(),DateAdd("yyyy",Year(Date())-Year([People].[Brithdate])+1,[Peopl
e].[Brithdate]),DateAdd("yyyy",Year(Date())-Year([People].[Brithdate]),[Peop
le].[Brithdate])) AS Birthday
FROM People
WHERE (((People.Brithdate) Is Not Null) AND
((IIf(DateAdd("yyyy",Year(Date())-Year([People].[Brithdate]),[People].[Brith
date])<=Date(),DateAdd("yyyy",Year(Date())-Year([People].[Brithdate])+1,[Peo
ple].[Brithdate]),DateAdd("yyyy",Year(Date())-Year([People].[Brithdate]),[Pe
ople].[Brithdate]))) Between Date() And DateAdd("m",1,Date())))
ORDER BY
IIf(DateAdd("yyyy",Year(Date())-Year([People].[Brithdate]),[People].[Brithda
te])<=Date(),DateAdd("yyyy",Year(Date())-Year([People].[Brithdate])+1,[Peopl
e].[Brithdate]),DateAdd("yyyy",Year(Date())-Year([People].[Brithdate]),[Peop
le].[Brithdate]));

Please post back if it still doesn't work (or even if it does :) )

Debra


Rli said:
Hi Debra, thank you for 'jumping in'.

But does your query give the birthday 15/01/2006 on systemdate 16 december
2005 when someone was born on 15/01/1960 ???
I dont think so because it will test on birthday 15/01/2005 and not 15/01/2006

you see what i mean?

Debra Farnham said:
Sorry to jump in here, but I've been watching the thread for a bit out of
interest and have found that this works:


SELECT People.Birthdate,
DateAdd("yyyy",Year(Date())-Year([People].[Birthdate]),[People].[Birthdate])
AS Birthday
FROM People WHERE (((People.Birthdate) Is Not Null) AND
((DateAdd("yyyy",Year(Date())-Year([People].[Birthdate]),[People].[Birthdate
])) Between Date() And DateAdd("m",1,Date())));

HTH

Debra

Yes....that helps...it actually does not give the error anymore

But it does not give me the right birthdays coming for the next month


:

Do you have any rows in your table where birthdate is null?

I just ran the exact query as a test, and I got the same error message
as
you for Null dates. Adding "AND People.Birthdate IS NOT NULL" solved it
for
me...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Yes, thought it should, but it does give an error: for instance

SELECT people.birthdate,
DateAdd("yyyy",Year(Now())-Year(people.birthdate)+1,people.birthdate)
AS
birthday
FROM people
WHERE
DateAdd("yyyy",Year(Now())-Year(people.birthdate)+1,people.birthdate)
Between now() And DateAdd("m",1,NOW());


gives the error (sorry, in french...) "Type de données incompatible
dans
l'expression du critère" (in short...incompatible types in the
criteria,
Error 3464)
OR no records at all......

When i remove the WHERE part it works fine and gives birthday for all
records.

But as soon as i use "Dateadd.... between .. and.." as a criteria it
fails
for incompatible types
[Birthdate] is a date field....and i did not create any of the objects
you
mention.

can you see why?
But still even if this does work, it would not give me all the
brithdays
for
next month...

So the initial question how to retrieve birthdays still stands....

:

Assuming [birthday] is a date field (as opposed to a text field),
that
should work.

One thing that could be causing a problem is if you've created any
objects
(variables, controls on forms, fields in tables, etc.) named Year,
Month
or
Day.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



i tried:
WHERE DateSerial(Year(now()),Month([birthday]),Day([birthday]))
BETWEEN
now() AND DateAdd("m",1,now())

but that gave me an error of incompatible types and
it will not work for birthday 10 january 1950 when it is now 15
december
2005

so what to do??? can anyone help?

:

thanks for your reply, but that does not seem to work....
it gives me only dates that are between date() and date()+31 not
anniversaries of dates (by the way...some months have 28,30 days
not
31)
so any other suggestions?

:

In your query, enter the following criteria in your birthdate
column
between date() and date()+31 This will give you the dates for
the
next
31
days.

--
Allan Murphy
Email: (e-mail address removed)
I have a table with birthdate of persons
I would like to write a query giving me all anniveraries
coming up
within
one month from now.
Can someone help me with this?
 
Since you didn't indicate that you want to identify which anniversary (1,
10, etc), another alternative is to create a function and pass it the
values. I function I have for this purpose, which I have provided below.
There are a couple of advantages to this function:

1. you are not limited to next month, you just have to pass it any two
dates.
2. much easier to read and maintain

To call the function in a query just add a column:

IsAnniversary([Birthday], #1/1/06#, #1/31/06#)

If you actually want to know which anniversary, then you can change the
IsAnniversary function to an Anniversary function by changing the Return
data type to variant (you probably want to return a Null if the anniversary
does not fall between the two dates) and determining the number of years
difference using the datediff( ) function in the sections of code where I am
currently setting IsAnniversary to True.

HTH
Dale

Public Function IsAnniversary(SomeDate As Variant, _
StartDate As Date, _
EndDate As Date) As Boolean

Dim intDay As Integer
Dim intMonth As Integer

If IsNull(SomeDate) Then
IsAnniversary = False
Exit Function
End If

intDay = Day(SomeDate)
intMonth = Month(SomeDate)
If DateSerial(Year(StartDate), intMonth, intDay) >= StartDate _
And DateSerial(Year(StartDate), intMonth, intDay) <= EndDate Then
IsAnniversary = True
ElseIf DateSerial(Year(EndDate), intMonth, intDay) >= StartDate _
And DateSerial(Year(EndDate), intMonth, intDay) <= EndDate Then
IsAnniversary = True
Else
IsAnniversary = False
End If

End Function
 
Back
Top