CODE
// Return number of days since 2000-01-01
integer datestamp(integer year, integer month, integer day){
year = year - 2000;
list monthdays = [0,31,28,31,30,31,30,31,31,30,31,30,31];
integer i=1;
integer sum = year * 365 + (year/4) + day;
for(i=1;i<month;i++){
if( (month != 2) || (year % 4 != 0)){
sum+=llList2Integer(monthdays,month);
}else if(month == 2){
sum+=29;
}
}
if(year % 4 == 0){
return sum - 1;
}
return sum;
}
// Convert the SL date string type (yyyy-mm-dd) to days since 2000-01-01
integer date2datestamp(string date){
integer year = (integer)date;
integer month = (integer)llGetSubString(date,5,6);
integer day = (integer)llGetSubString(date,8,9);
return datestamp(year,month,day);
}
// Get someone's age in days based on the current date (PST)
integer getAge(string timestr){
integer todayDate = date2datestamp(llGetTimestamp());
integer agentBirthDate = date2datestamp(timestr);
return todayDate - agentBirthDate;
}
This would be good for using internally when I compare an avatar's age against a list of age groups.
However, when I report the age back to the user, I need to convert the number of days into number of years, months, and days. Is there an easy way to do this from the number of days? or should I use a different function to turn the date of creation into years, months and days?
Thanks for your help.
Edit - Ok, just found another script that does the same as above.. in a different mannor. I'll compare the two and see which I like better. I take it there isn't any good way of converting days old into years, months, and days old?
I suppose, I could just assume an average of.. say 30 days to a month.. but that won't always come out right.
I guess I'll have to write something.. based on the script above.. that will look at current month and day, and use that to work backwards and get correct info.. Or i'll just stick with days old as norm.
Thanks all.