473,396 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Calculate the difference between two dates

Access 2003 - I am trying to calculate the difference between a specific date 5/1/2007 (not in a data field) and other dates that ARE in a field called Birth Date. I am trying to have it fill into an Age field (in years only) by comparing the date above to the Birth Date field. I have tried this and it doesn't work:

=DateDiff("yyyy", [Birthday1], [Birthday2]) Displays the variance in years between the values of the Birthday1 and Birthday2 fields. (from Access help screen).

I have tried it several ways:

1) =DateDiff("yyyy", [5/1/2007], [Birth Date])

2) =DateDiff("yyyy", 5/1/2007, [Birth Date]) because 5/1/2007 is not a field name

3) setting up a field with 5/1/2007 in every record and doing #1

Nothing is working - getting errors - please help
Nov 16 '06 #1
8 17552
nico5038
3,080 Expert 2GB
Check: http://www.mvps.org/access/datetime/date0001.htm
Many fine other samples there too.

Nic;o)
Nov 16 '06 #2
Hi,

I am trying diligently and getting this error:

Invalid Syntax error - cannot use multiple columns in a column-level CHECK constraint.

this is what I did: in the Validation Rule for Field name Age

=DateDiff("yyyy",(5012007),[Birth Date])

5/1/2007 is just the date I am comparing the birth dates to. It is nowhere else in the db.....can you help?
Nov 16 '06 #3
nico5038
3,080 Expert 2GB
Try:

=DateDiff("yyyy",#5/1/007#,[Birth Date])

and make sure the field with this statement isn't named [Birth Date] :-)

Nic;o)
Nov 16 '06 #4
Hi, see I really am helpless!!

I put this validation rule into the Age field:

=DateDiff("yyyy",#5/1/2007#,[Birth Date])

and I am still getting the same error. It looks like it thinks 5/1/2007 is a column/field, but it is not.

thanks anyway!
Nov 16 '06 #5
nico5038
3,080 Expert 2GB
Hmm, perhaps your separator is ; instead of a ,
Try:
=DateDiff("yyyy";#5/1/2007#;[Birth Date])

Nic;o)
Nov 16 '06 #6
Hi,

Thanks, I tried that, but then it gives me an invalid syntax error.

that's ok, I think I'll keep putting in the dates manually!

thanks
Nov 16 '06 #7
MMcCarthy
14,534 Expert Mod 8TB
Hi,

Thanks, I tried that, but then it gives me an invalid syntax error.

that's ok, I think I'll keep putting in the dates manually!

thanks
This is not as straight forward as it first seemed

=DateDiff("yyyy", #5/1/2007#, [Birth Date])

The probem is that as of 1st January it will count the year so age won't be calculated correctly.

You need to adapt it as follows:

=DateDiff("yyyy", Format(#05/01/2007#,"Short Date"), IIf(Format([Birth Date], "mmdd") >= Format(#05/01/2007#,"mmdd"),[Birth Date],[Birth Date] + 1))

BTW, where exactly are you putting this calulation?

Mary
Nov 17 '06 #8
NeoPa
32,556 Expert Mod 16PB
Mary is right, but the more fundamental problem of why the 'Validation Rule' actually throws up an error when you enter
Expand|Select|Wrap|Line Numbers
  1. =DateDiff("yyyy",#5/1/007#,[Birth Date])
is very confusing.
I have
Expand|Select|Wrap|Line Numbers
  1. =DateDiff("yyyy",#01/05/2006#,[EndJob])
working fine in my test db.
Nov 18 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: David Gray | last post by:
Greetings all, Quick newbie type question: I would like to be able to trap non-numerical data entered into a textbox via CTRL+C and/or Shift+Insert. I realise that this data can be...
4
by: Manny Chohan | last post by:
Hi Can anyone tell me how i can calculate yesterday date using asp? Thanks manny
26
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: ...
5
by: SimonC | last post by:
Help needed for a Javascript beginner. As above in the subject... i need a javascript to run this, but not in the form of a web-page. I want to calculate it between 2 fields in a database that...
1
by: bradleyc | last post by:
How would you calculate the difference between two dates?
2
by: Steve | last post by:
Hi all How would I find out the average date when given a bunch of dates? For example, I want to find the average length in time from the following dates:...
5
by: infobescom | last post by:
Hi I am wrking on a application where i need to calculate the difference between two dates .. here is the formula i am using ........ Public Function GetNumberOfWorkDays(sStartDate,...
7
by: walt | last post by:
Hello, I have been trying to calculate the difference between two date and display the difference in hours and minutes (HH:MM). I can't get it calculate properly and I can't hours and minutes to...
4
by: lenygold via DBMonster.com | last post by:
I found this example in MYSQL: create table events ( id integer not null primary key , datetime_start datetime not null , datetime_end datetime not null ); insert into events values ( 1,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.