Quote:
Originally Posted by ecca
Ok really dont understand that code to 100% so can you give me an example how to use it to?
|
OK. example:
PHP Code:
public OnPluginStart()
{
decl String:date1[]="2011-12-24";
decl String:date2[]="2011-12-22";
LogMessage("ConverDate: %s to %s is %d", date1, date2, ConvertDate(date1, date2));
}
stock ConvertDate(String:date1[], String:date2[])
{
ReplaceString(date1, strlen(date1)+1, "-", ""); // replace 2011-12-22 to 20111222
ReplaceString(date2, strlen(date2)+1, "-", "");
decl String:strYear[2][5], String:strMonth[2][3];
strcopy(strYear[0], sizeof(strYear[]), date1); // strYear[0] = "2011"
strcopy(strYear[1], sizeof(strYear[]), date2);
ReplaceString(date1, strlen(date1)+1, strYear[0], ""); // date1 = "1222"
ReplaceString(date2, strlen(date2)+1, strYear[1], "");
strcopy(strMonth[0], sizeof(strMonth[]), date1); // strMonth[0] = "12"
strcopy(strMonth[1], sizeof(strMonth[]), date2);
ReplaceString(date1, strlen(date1)+1, strMonth[0], ""); // date1 = "22"
ReplaceString(date2, strlen(date2)+1, strMonth[1], "");
if (!strlen(date1)) strcopy(date1, sizeof(strMonth[]), strMonth[0]); // if month == day, exampel "20110808"
if (!strlen(date2)) strcopy(date2, sizeof(strMonth[]), strMonth[1]);
// (year1 - year2)*365 + (month1 - month2)*30 + (day1 - day2)
return (StringToInt(strYear[0]) - StringToInt(strYear[1])) * 365 + (StringToInt(strMonth[0]) - StringToInt(strMonth[1])) * 30 + (StringToInt(date1) - StringToInt(date2));
}
result:
PHP Code:
L 12/23/2011 - 09:43:13: [new.smx] ConverDate: 24 to 22 is 2
__________________