Modules & VBA :: Getting Age In Years With One Decimal Place (3.5 Years)
Mar 24, 2014
I have a table that lists computers I want to know the age of them for replacement purposes. I am using this function to populate a textbox on a form that updates my table. the results I am getting is a negative whole number I would like to get a positive number with one decimal place. so if computer was shipped September 24, 2010 my textbox would say 3.5 not -3
Here is my function
Code:
Private Sub Form_Load()
Dim theDate As Date
Dim age As Integer
theDate = Nz(Me.compDate.value, 0)
If theDate > 0 Then
age = DateDiff("yyyy", Now(), theDate)
Me.compAge = age
End If
End Sub
View Replies
ADVERTISEMENT
Apr 19, 2014
I have this code for calculating the age from birthdate but i want if there is years no months or days appear
Public Function CalcAge(Birthdate As Date) As String
Dim intYears As Integer, intMonths As Integer, intDays As Integer
intMonths = DateDiff("m", Birthdate, Date)
intDays = DateDiff("d", DateAdd("m", intMonths, Birthdate), Date)
[Code] ....
View 4 Replies
View Related
Jul 19, 2013
Find the difference between two dates is simple if you're simply looking for the number of days between them. However, if you're looking to express the difference in a bit more user-friendly way, you can use the following code to calculate the difference in years, months, and days. The code accounts for zero values, plurals and the Oxford comma. Further, it automatically sets the later of the two dates to the End date, so the dates can be used interchangeably.
Examples:
June 4, 2010, July 3, 2012 returns "2 Years and 29 Days"
June 4, 2010, July 5, 2011 returns "1 Year, 1 Month and 1 Day"
June 4, 2010, June 5, 2010 returns "1 Day"
Code:
Function DiffOfTwoDates(dtmDate1 As Date, dtmDate2 As Date) As String
' Written by Will Knapp, Freelance Access Developer, 2013
Dim dtmStart As Date, dtmEnd As Date
Dim strDiff As String ' Resulting String
Dim yDiff As Integer ' Year Difference
Dim mDiff As Integer ' Month Difference
Dim dDiff As Integer ' Day Difference
Dim CommaLoc As Integer
[code]....
View 3 Replies
View Related
Sep 4, 2013
My DB is merge in a currency field set to 2 decimal places into word. It's doing this by declaring the fields as variable, calling an instance of work then dropping the values into the bookmarks. All works fine....
When a value is 360.64 is fine, but when it's something that ends with a 0 (360.60) - is loses the 0 giving me 360.6.
View 2 Replies
View Related
Oct 29, 2007
Hello mates, :cool:
I'm a bit confused with date codes. What I'm try to complish here is that how to add years and months from separate fields to text box, where's difference between two dates as an years and months? So basicly first I read year and month values from text boxes to a integer and then I'm going to add them to somewhere at last, but I'll get like 1 year and 14 months for result so, could you hit me with some tips or tricks what I should try out.
I'll approciate your time to help me out with this and thanks for advance. =P
View 1 Replies
View Related
Feb 14, 2007
Firstly, when designing tables, how can I format Date/Time to just the Year? I've tried syntax yyyy, but when I enter a year after opening the table, I get a type mismatch error.
Secondly, providing I have the correct custom format for Year, how can I enter the following dates?
1744-1745
Circa 1925
Before 1690
1800s
And would I be able to run queries on them, showing the dates in ascending order?
Any help would be much appreciated!
View 2 Replies
View Related
Oct 2, 2007
Hi,
I would like to be able to run a query that lists the number of years members have been subscribing (up to the current year).
i.e. to show the year he joined, and how many years he has been a member (shown as a number).
Is there a way to do this easily?
thanks
Adrian
View 2 Replies
View Related
Dec 5, 2007
I have atable the is storing ID, attendance_year and meeting code. Iw ould like to query the table and identify the IDs that have 10 consecutive attendance years no matter when it may have occured. So IDs have more than 10 row of data but not necassrily 10 years in a row.
How can I do this?
table looks like
123|2003|WIN03
123|2001|SUM02
456|2001|WIN01
456|2000|WIN00
456|2002|SPR02
456|2006|SUM06
View 5 Replies
View Related
Dec 31, 2004
Happy New Years guys, all the best. hope the year will be good to us all.
View 1 Replies
View Related
Oct 31, 2006
How do I set up a query to sum data separately by year in the same row of data? I would like to see on one row a sum for year 2005 and also a separate field to sum for 2006.
Help me please!
EWJRichardson
View 4 Replies
View Related
May 10, 2005
I’m after some database advice. It will probably be something simple I can’t see for the wool…
I’m putting together a database that describes specifis small area geographies (Scottish Census output areas). For small area there will be various training category variables with associated counts and a general cost for all training in that geography. On its own this isn’t really a trouble but the database will grow over time with the same data (more or less) appearing each year to add to the database. I have a master geographical index that is used to aggregate small area data to higher areas so I could :-
- have a series of year based tables linked through the small area field and queried on a year look up basis.
- store each years data into the same table as the last and use a year identified to separate the records
- add new fields for all variables for each year across one table although once the number of fields reach 255 or so it would fall to bits.
I think the third is the worst option but I really would be grateful if anyone had any thoughts you could share with me on the best design approach to take.
Any help gratefully received!
Thanks...
View 1 Replies
View Related
Aug 22, 2005
Need some help figuring out the best way to handle this.
I have one table - tblEngineVolumes which has columns for each month Jan-Dec for the year 2005 with fields for each printer type.
Type Jan Feb Mar.....
PrinterA 100 50 300
PrinterB 500 25 250
I now have to figure out a way to have both 2005 and 2006 volumes for each printer.
My option so far is are below (there will never be any more than 2 years involved)
Type Jan 05 Jan 06 Feb 05 Feb 06
PrinterA 100 150 50 60
PrinterB 500 400 25 35
OR
Type Year Jan Feb
PrinterA 2005 100 50
PrinterA 2006 150 60
PrinterB 2005 500 25
PrinterB 2006 400 35
Would appreciate any thoughts/suggestions
Thanks,
Toni
View 2 Replies
View Related
Dec 4, 2007
Hi,
I have the following function:
Function GetFiscalYear(ByVal x As Variant)
If x < DateSerial(Year(x), FMonthStart, FDayStart) Then
GetFiscalYear = Year(x) - FYearOffset - 1
Else
GetFiscalYear = Year(x) - FYearOffset
End If
End Function
I call on the function in my query to determine the FiscalYear for a date.
Expr1: GetFiscalYear([ProdDate])
It sends back the correct Fiscal Year. However, when I try to put criteria in for Expr1 to show only Fiscal Year 2007 instead of all fiscal years, it gives me a data mismatch type error.
The [ProdDate] has the following formula:
Prod_Date: IIf([40Day]="True",DateAdd("d",-40,[Date Code]),DateAdd("d",-50,[Date Code])) where [40Day] returns True or False to determine if I should subtract 40 or 50 days from the Date Code. The Date Code is in the format ##/##/#### and is sometimes null.
I have tried everything I could think of and am completely stumped. Thanks in advance for any help!!!
View 2 Replies
View Related
Mar 5, 2008
Hi,
How do I query the last 2 years vs. current date?
Basically, I want to see the record from today date back to 2 years.
Please assist...
Thanks,
Isabel
View 3 Replies
View Related
Oct 11, 2005
Hi folks,
I want to populate a drop down combo box with a list of 10 years (current year +/- five years). I can enter them as a Value list but I don't want to have to update the list every year. Neither do I want to allocate a table to maintain a list.
Any ideas as to how I can auto populate the combo with a 10 yr span (5 previous and 5 next) and default to current year?
Thanks,
Dave
View 9 Replies
View Related
May 20, 2006
I hope someone will be able to help....
I have minimum year and maximum year value (for example 2006 is minimum & 2009 is maximum. How could I get a combo box to display all the years within the range of the minimum and maximum year (in this case, it should give me an option of 2006, 2007, 2008, 2009).
FYI - This database is used to track projects and each project has a commencement date and an estimated completion date. the minimum year is derived from the commencement date and the maximum date is derived from the estimated completion date. I am building a search form whereby the year selected in the combo box should display all the projects commencing, continuing, and ending that year.
Pls help...
Thanks in advance.
jan :confused:
View 8 Replies
View Related
Feb 8, 2005
I need a formula or a function that will return a person's age in years and months. All the functions and formulas that I have seen to date and that I have used only calculate a person's age in years. Can anyone help?
View 2 Replies
View Related
Jan 25, 2006
Friends,
I have a form with four fields, date1, date2, date3 and date 4.
These have all a mm/dd/yyyy format.
I need to add an unbound control which will count in months and years the difference between the dates.
Ex.
date1: 01/01/1970
date2: 05/05/1980
date3: 06/06/1990
date4: 06/30/2001
Fields date3 and date4 may be blank, therefore the code should consider only counting the first two.
Thanks for any help.
View 14 Replies
View Related
Jan 5, 2007
Hi,
i have a displayed(textbox) birthdate (txtDoB) and a textbox "input_date" (txtInputDate) inside form "form Two".
how do i calculate the years and months difference upon clicking the "OK" command button at "form Two"?
the result of the years and months will be displayed at a textbox (txtResult) at a form called "form Result".
thank you.
View 2 Replies
View Related
Apr 25, 2005
I have a burron to run a query that auto populates 'start time' with NOW().
It has worked for 3 years and now I get an error message see attached. The only thing I did was change the program fromm 2000 to 2002.
any and all suggestions welcome.
Thanks
View 2 Replies
View Related
Jul 11, 2006
Hello,
I am building a Db that will report against individual transactions. Each transaction will be on a specific day.
Now I will need to slice and dice the data in a number of different ways depending on what the end user wants to see.
Therefore I need to build a date table that will aggregate all the individual days by Week, Month, calendar year, fiscal year...etc.
Being a rookie, I was simply going to build a table that has all the days for the last three years and then the corresponding weeks, months etc in columns to the right.
Because of this design, I will have over 1,000 records. Could I do it differently to keep the size of the table down?
For example use ranges as a cell value (Our week 1 is named "Feb 1st Wk", it is 1/30/06-2/5/06 for fiscal Yr 2006, 1/31/04-2/6/05 for fiscal Yr 2005...etc)
Any advice on this?
Thanks, Paul
View 5 Replies
View Related
Jun 3, 2005
hi, i want to calculate how long each person has worked at a company.
i am using access 97.
would i be able to enter something in the criteria that would work this out for me?
something like year([START DATE]) - year(Now())
this does not work but i want to find out the number of years a person has worked for the company from the field START DATE .
thanks for you help.
View 8 Replies
View Related
Aug 17, 2005
I have a database that I am using to report metrics based on seasonally available data. What I am running into is the problem that the seasonally entered data doesn't start on the same date every year.
An example:
I have data that was entered into my database last year starting July 26, 2004. This is considered part of week 1 of my season and I want to compare that data to records that started being entered on August 15, 2005. Which is week 1 of the 2005 season.
Records include the following information: id, date, other irrelevant details
Does anyone have any ideas on how I might be able to accomplish this? Thanks in advance for your help!
View 1 Replies
View Related
Dec 29, 2005
I have a table with these 2 fields: Name and AnniversaryDate. What is the best way to write a query that will show me all the anniversaries that will fall within the next two weeks?
For instance if I have a record with these values:
Name, Anniversary
BukHix, 1/1/2003
I want the query to look at today’s date, which in this case would be 12/29/2005 go two weeks forward, which would make it 1/12/2006 and show any anniversary date that would fall between the dates.
The catch (and the part that is throwing me off) is how do I do that without explicitly naming the year? I mean I need to catch every date in that range from 1965 to Current year - 1.
Any ideas?
View 4 Replies
View Related
Jun 5, 2006
I have a form that I'd like to place a date onto, after entering a from date and a to date. What I'd like to see on the form, after entering my two specified dates, is:
"You have xx years, yy months and zz day left on your timeline." where xx is the number of years, yy the number of months andzz the number of days.
If I entered dates of say, 01/01/01 for my from date and 12/31/06 as my to date, how can I accomplish something like what I want?
Thank you so much in advance! I'm looking forward to your suggestions!!!!
View 2 Replies
View Related
Feb 8, 2005
I'm trying to calculate the amount of years employed in a query and I keep getting "Data Type Mismatch in criteria expression".
I'm putting the expression in the YearsOfService Field that I've created that I would for the total in years to populate.
Here's the field expression:
DateDiff("yyyy",[EmpHireDate],Date())+(Date()<DateSerial(Year(Date()),Month([EmpHireDate]),Day([EmpHireDate])))
Thanks for any help...
FYI EmpHireDate is a Date/Time Field and YearsOfService is a Number field
Thanks for any help...
View 12 Replies
View Related