PC Review


Reply
Thread Tools Rate Thread

Date of birth question

 
 
Lillian
Guest
Posts: n/a
 
      6th Nov 2007
I receive a table from the main office and it has a Date of Birth field that
is formated text and as yyyy/mm/dd. How do I make a query field as a real
date and time format as mm/dd/yyyy and filter for all ages less than 25
years old?

I have this for a criteria but I don't have a real date format for the DOB
field.

<=DateAdd("yyyy",-25,Date())
 
Reply With Quote
 
 
 
 
Anthos
Guest
Posts: n/a
 
      6th Nov 2007
On Nov 6, 1:56 pm, Lillian <libertysmit...@yahoo.com> wrote:
> I receive a table from the main office and it has a Date of Birth field that
> is formated text and as yyyy/mm/dd. How do I make a query field as a real
> date and time format as mm/dd/yyyy and filter for all ages less than 25
> years old?
>
> I have this for a criteria but I don't have a real date format for the DOB
> field.
>
> <=DateAdd("yyyy",-25,Date())


Try the CDate(Format([field], "yyyy/mm/dd")) then do your criteria
based on that.

Let me know how that goes, and if it helps.

Kind Regards
Anthony Moore

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      6th Nov 2007
On Mon, 05 Nov 2007 20:56:35 -0600, Lillian <(E-Mail Removed)> wrote:

>I receive a table from the main office and it has a Date of Birth field that
>is formated text and as yyyy/mm/dd. How do I make a query field as a real
>date and time format as mm/dd/yyyy and filter for all ages less than 25
>years old?
>
>I have this for a criteria but I don't have a real date format for the DOB
>field.
>
><=DateAdd("yyyy",-25,Date())


Either convert the criterion to a text string matching your text date (which
is fortunately of a form that is chronological):

<= Format(DateAdd("yyyy", -25, Date()), "yyyy/mm/dd")

or convert the text date to a real Date/Time field:

CDate([Date of Birth])

and omit the Format expression from your criterion.

The first option will have better performance if the table is large and the
field is indexed.

Your best bet would be to add a genuine date/time field to the table and run
an update query to populate it using CDate().

John W. Vinson [MVP]
 
Reply With Quote
 
Lillian
Guest
Posts: n/a
 
      6th Nov 2007
John W. Vinson wrote:

> On Mon, 05 Nov 2007 20:56:35 -0600, Lillian <(E-Mail Removed)>
> wrote:
>
>>I receive a table from the main office and it has a Date of Birth field
>>that
>>is formated text and as yyyy/mm/dd. How do I make a query field as a real
>>date and time format as mm/dd/yyyy and filter for all ages less than 25
>>years old?
>>
>>I have this for a criteria but I don't have a real date format for the DOB
>>field.
>>
>><=DateAdd("yyyy",-25,Date())

>
> Either convert the criterion to a text string matching your text date
> (which is fortunately of a form that is chronological):
>
> <= Format(DateAdd("yyyy", -25, Date()), "yyyy/mm/dd")
>
> or convert the text date to a real Date/Time field:
>
> CDate([Date of Birth])
>
> and omit the Format expression from your criterion.
>
> The first option will have better performance if the table is large and
> the field is indexed.
>
> Your best bet would be to add a genuine date/time field to the table and
> run an update query to populate it using CDate().
>
> John W. Vinson [MVP]



I'm sorry it is a number format not a text format.

I have to import the date.txt file and use an import specification. I tried
to import as a date field but it fails and the DOB field is blank. Is
there away of changing the Number format to a date format in the import
specification? I can see how at this time. I all tried to make another
table and append to it. The number DOB field won't append to the Date
format DOB Field in the other table.

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      6th Nov 2007
On Tue, 06 Nov 2007 06:23:07 -0600, Lillian <(E-Mail Removed)> wrote:

>I have to import the date.txt file and use an import specification. I tried
>to import as a date field but it fails and the DOB field is blank. Is
>there away of changing the Number format to a date format in the import
>specification? I can see how at this time. I all tried to make another
>table and append to it. The number DOB field won't append to the Date
>format DOB Field in the other table.


I'd suggest using a Link to the text file (rather than an import); base an
Append query on the linked table, and use a calculated expression to parse the
number into a date. I presume that what's actually stored in the text file is
a number like 20071106? If so, it will not be recognized as a date; you'll
need an expression like

CDate(Format([datefield], "0000/00/00")

or

DateSerial([datefield] \ 10000, [datefield] MOD 10000 \ 100, [datefield] MOD
100)

as a calculated field in the append query.

John W. Vinson [MVP]
 
Reply With Quote
 
Lillian
Guest
Posts: n/a
 
      7th Nov 2007
John W. Vinson wrote:

> On Tue, 06 Nov 2007 06:23:07 -0600, Lillian <(E-Mail Removed)>
> wrote:
>
>>I have to import the date.txt file and use an import specification. I
>>tried
>>to import as a date field but it fails and the DOB field is blank. Is
>>there away of changing the Number format to a date format in the import
>>specification? I can see how at this time. I all tried to make another
>>table and append to it. The number DOB field won't append to the Date
>>format DOB Field in the other table.

>
> I'd suggest using a Link to the text file (rather than an import); base an
> Append query on the linked table, and use a calculated expression to parse
> the number into a date. I presume that what's actually stored in the text
> file is a number like 20071106? If so, it will not be recognized as a
> date; you'll need an expression like
>
> CDate(Format([datefield], "0000/00/00")
>
> or
>
> DateSerial([datefield] \ 10000, [datefield] MOD 10000 \ 100, [datefield]
> MOD 100)
>
> as a calculated field in the append query.
>
> John W. Vinson [MVP]



Ok. It is working. I linked the table then append to another one like it
with the DOB field formated Date. Then the criteria finally did work.
Plus it is very accurate total of records with all under 25 years old.
Very amazing to see this.

I'll try the other CDate functions above and see if they work too.

 
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
Querying question with regards to birth date JeannieC Microsoft Access 6 3rd Oct 2008 08:11 PM
.NET DateTime Purchase Date and Birth Date shifting =?Utf-8?B?QyBWaWxsYWxiYQ==?= Microsoft Dot NET 3 20th Jul 2006 06:58 AM
how to write; specific date minus date of birth equals years =?Utf-8?B?anVzdCBhbm90aGVyIE1pa2U=?= Microsoft Access Queries 7 18th Mar 2006 03:56 AM
Acces 2003: Substraction between date of birth and system date =?Utf-8?B?Sm9oYW4=?= Microsoft Access Forms 4 17th Feb 2006 01:27 PM
formula to calculate age using birth date and current date =?Utf-8?B?bGFsYWg=?= Microsoft Excel Worksheet Functions 2 20th Nov 2005 10:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:12 AM.