Matlab Program to determine Age of object

Click For Summary
SUMMARY

The discussion focuses on creating a Matlab program to calculate the age of an object in days based on user-provided creation and current dates. The program requires six user inputs: year, month, and date for both the creation and today's date. The user has implemented functions to determine the number of days in a month and to check for leap years, but is seeking guidance on how to proceed with the age calculation logic after the input statements. Key challenges include correctly handling the month and date comparisons, especially when accounting for leap years in February.

PREREQUISITES
  • Understanding of Matlab programming syntax and functions
  • Knowledge of date and time manipulation in programming
  • Familiarity with leap year calculations
  • Basic logic for conditional statements and iterations
NEXT STEPS
  • Implement a function to calculate the total number of days from the creation date to today's date
  • Research Matlab's built-in date functions for improved accuracy
  • Learn about handling edge cases in date calculations, particularly for February
  • Explore iterative methods for summing days across months
USEFUL FOR

This discussion is beneficial for students learning Matlab, software developers working with date calculations, and anyone interested in programming logic for age determination based on dates.

bengaltiger14
Messages
135
Reaction score
0

Homework Statement



Write a program to determine the age of an object given the creation date and todays date. The program must contain 6 user input statements (asking for year, month and date of creation, and year,month, todays date) and display the age of the object in days.

I have already written functions to determine how many days are in a month and to determine if a year is a leapyear. The days in month function has the leap year function inside of it in cases of february

I have the 6 input statement written and I am now stuggling with the code.

I have this after the input statements:

if month1 > month2 || ((month1==month2) && (date1>date2))
years = (year2 - year1) - 1

Where do I go from here and am I even doing this correctly?

Month 1 is the creation month, month 2 is todays month, date 1 is creation date and date2 is todays date.
 
Physics news on Phys.org
You know how many days are in a particular year, so all you have left is to calculate the number of days in the fraction of a year you have left. Just iterate through the months and add the days, keeping track of which year february is in if you happen to pass over a february in this fractional year. That's the trickiest part easily.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
7K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
11K
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
7K
Replies
9
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K