okay, example.
I have: 18-03-2016
And i have a function and in the function is possible add days, month and years (with params)
if i add 14 days and 4 months,
the days following that format will be: 32-07-2016
i need make function to add days/months/years correctly
i thought in months conversion to days and operate so.. but the problem is with the leap-years.
I also thought in convert the date to unixtime, add the time and convert the unix time to dd-mm-yy, but i not know, i have a lot problems with this..
The programming language is "PAWN", similary with C.. but in this programming language we not having POO (I mention this so they know when basic is this programming language, only is based on logic and basic structure .. for, if, else, case, etc ..), not exist functions like strpftime, strtototime, date(.., etc.
i make this functions to conversion..
stock DateToStamp(_day, _month, _year)
{
new total = 0;
new tmp = 0;
total += _day * 86400;
tmp = ((_year - 1968)/4)-((IsLeapYear(_year) && _month == 2) ? 2 : 1);
total += tmp * 31556926;
total += (_year - 1970 - tmp) * 31536000;
for(new i = 1; i < _month; i ++)
{
total += getTotalDaysInMonth(i, _year) * 86400;
}
total += 630214;
return total;
}
stock StampToDate(timestamp, &_day, &_month, &_year)
{
new year = 1970;
new day = 1;
new month = 1;
timestamp += 86400;
while(timestamp > 31536000)
{
timestamp -= 31536000;
if(IsLeapYear(year))
{
timestamp -= 86400;
}
year++;
}
while(timestamp > 86400)
{
timestamp -= 86400;
day++;
if(day == getTotalDaysInMonth(month, year))
{
month++;
}
}
printf("%i-%i-%i", day, month, year);
_day = day;
_month = month;
_year = year;
return 1;
}
stock GetTotalDaysFromYear(year)
{
return IsLeapYear(year) ? 366 : 365;
}
and i think in make that function based in logic.. but not work, my idea was it get months and divide with 12 (in case which we have a decimal number.. 1.0435, take the 1 and 0.0435 separated to multiply for 12 and get subs-days.. but i not know if that is the best method..
stock GetDateDateAddingDays(days, months, years, _day, _month, _year, &dia, &mes, &year)
{
printf("--------------");
// Obtener los meses generales;
new meses_generales = months;
new d, month_s;
new Float:obtener_operado = float(meses_generales)/12;
printf("%f", obtener_operado);
new get_entero = floatround(obtener_operado, floatround_floor);
printf("%i", get_entero);
new Float:obtener_decimales = obtener_operado-get_entero;
printf("[deb - f] %f - %f", obtener_operado, obtener_decimales);
new get_dias_from_meses = floatround(obtener_decimales * 12, floatround_floor);
printf("dias: %i", get_dias_from_meses);
/*
new get_days;
new day_residuo = floatround(f, floatround_ceil)/12;
new operable = f/12;
printf("[deb - day_residuo] %f", operable);
operable = operable-floatround(f, floatround_ceil);
new res = f_s - operable;
new month_s = f_s - f;
printf("[deb] %f - %f - %f", operable, f_s, f);
if(f > 0)
{
printf("____________ PRIMA ______________");
printf("[deb] %i", get_days);
get_days += floatround(f * 12, floatround_ceil);
printf("[deb] %i", get_days);
printf("____________ PRIMA ______________");
}
new d = days + get_days;
*/
printf("[deb] %i - meses %f - ages = %i", d, month_s, years);
/*
for(new m; m = months; m++)
{
for(new d = 1; d <= getTotalDaysInMonth(m, _year); d++)
{
days ++;
if(days == getTotalDaysInMonth(m, _year))
{
mes ++;
}
if(mes >= 12 && days >= 31){
year ++;
}
}
}
*/
/*
new tiempo = DateToStamp(_day, _month, _year);
tiempo += (days * 86400) + (months * 2592000) + (years * 31536000);
StampToDate(tiempo, dia, mes, year);*/
printf("--------------");
return 1;
}