PC Review


Reply
Thread Tools Rate Thread

comparing a date with "today" in ACCESS Query

 
 
Ian
Guest
Posts: n/a
 
      27th Jan 2010
My table has a DOB date. I wish to compare it with today, and count those
rows where DOB is under 16 years, and also count those greater than 16 years.
I thought this would work : datediff("yyyy", CurrentDependents.DOB, Date())
< 17
and datediff("yyyy", CurrentDependents.DOB, Date()) > 16. Alas not.
If I set DOB to 01/01/1994, I get < 17 set to 1, and > 16 set to 0.
If I set DOB to 31/12/1993, I get < 17 set to 0, and > 16 set to 1.
So my syntax is only looking at the year element of the date, and not the
whole date.
Can anyone advise please ?
Many thanks

--
newUser51
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      27th Jan 2010
DateDiff works by counting the number of changes that occur between the two
dates. DateDiff("yyyy", #2009-12-31#, #2010-01-01#) will report a 1 year
difference since the year changed between the two dates, even though there's
only a 1 day difference.

Use DateAdd to figure out when they turn 16:

DateAdd("yyyy", 16, DOB)

and compare that to today's date.

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"Ian" <(E-Mail Removed)> wrote in message
news1D0943C-A818-4219-BE80-(E-Mail Removed)...
> My table has a DOB date. I wish to compare it with today, and count those
> rows where DOB is under 16 years, and also count those greater than 16
> years.
> I thought this would work : datediff("yyyy", CurrentDependents.DOB,
> Date())
> < 17
> and datediff("yyyy", CurrentDependents.DOB, Date()) > 16. Alas not.
> If I set DOB to 01/01/1994, I get < 17 set to 1, and > 16 set to 0.
> If I set DOB to 31/12/1993, I get < 17 set to 0, and > 16 set to 1.
> So my syntax is only looking at the year element of the date, and not the
> whole date.
> Can anyone advise please ?
> Many thanks
>
> --
> newUser51



 
Reply With Quote
 
Ian
Guest
Posts: n/a
 
      27th Jan 2010
Many thanks Doug.
Query working a treat !
--
newUser51


"Douglas J. Steele" wrote:

> DateDiff works by counting the number of changes that occur between the two
> dates. DateDiff("yyyy", #2009-12-31#, #2010-01-01#) will report a 1 year
> difference since the year changed between the two dates, even though there's
> only a 1 day difference.
>
> Use DateAdd to figure out when they turn 16:
>
> DateAdd("yyyy", 16, DOB)
>
> and compare that to today's date.
>
> --
> Doug Steele, Microsoft Access MVP
> http://www.AccessMVP.com/DJSteele
> (no e-mails, please!)
>
> "Ian" <(E-Mail Removed)> wrote in message
> news1D0943C-A818-4219-BE80-(E-Mail Removed)...
> > My table has a DOB date. I wish to compare it with today, and count those
> > rows where DOB is under 16 years, and also count those greater than 16
> > years.
> > I thought this would work : datediff("yyyy", CurrentDependents.DOB,
> > Date())
> > < 17
> > and datediff("yyyy", CurrentDependents.DOB, Date()) > 16. Alas not.
> > If I set DOB to 01/01/1994, I get < 17 set to 1, and > 16 set to 0.
> > If I set DOB to 31/12/1993, I get < 17 set to 0, and > 16 set to 1.
> > So my syntax is only looking at the year element of the date, and not the
> > whole date.
> > Can anyone advise please ?
> > Many thanks
> >
> > --
> > newUser51

>
>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I show "Today" and "Yesterday" in my Date view? =?Utf-8?B?UGtiYXNl?= Microsoft Outlook Discussion 1 2nd Jul 2007 05:47 AM
How can I remove "Date: Today", "Date: Yesterday" in inbox? =?Utf-8?B?VW5pdHlHaXptbw==?= Microsoft Outlook Discussion 1 24th Mar 2005 05:12 PM
How can I remove "Date: Today", "Date: Yesterday" in inbox? =?Utf-8?B?VW5pdHlnaXptbw==?= Microsoft Outlook Discussion 2 23rd Mar 2005 06:47 PM
delete record if "date" < "today" Wax Microsoft Access Getting Started 2 16th Sep 2004 12:25 AM
Query that asks for dates x number of days away from today's date / comparing two fields in a query Mike H Microsoft Access Queries 2 22nd Dec 2003 08:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:11 AM.