provides stock to convert a date to seconds since Unix Epoch (01.01.1970)
attached test plugin
command to test "date_test" - only from server console or rcon
PHP Code:
stock DateToTimeStamp(day, month, year, hour, minute, seconds)
{
return YearToSeconds(year) + MonthToSeconds(year, month) + DaysToSeconds(day) + TimeToSeconds(hour, minute, seconds) - 21600; // Why it returns more by 21600?
}
stock YearToSeconds(year)
{
new var1 = year / 4;
new var2 = year - var1;
new var3 = var1 - 492;
new var4 = var2 - 1478;
var3 *= 31622400;
var4 *= 31536000;
return var3 + var4;
}
// 31 days = 2678400 seconds
// 30 days = 2592000
// 29 days = 2505600
// 28 days = 2419200
stock MonthToSeconds(year, month)
{
month -= 1;
new result;
switch (month)
{
case 1, 3, 5, 7, 8, 10 :
{
result = 2678400;
}
case 2 :
{
if (year % 4 == 0)
{
result = 2505600;
}
else
{
result = 2419200;
}
}
case 4, 6, 9, 11 :
{
result = 2592000;
}
}
if (month > 1)
{
result += MonthToSeconds(year, month);
}
return result;
}
stock DaysToSeconds(days)
{
days-=1;
return days * 86400;
}
stock TimeToSeconds(hour, minute, seconds)
{
return hour * 3600 + minute * 60 + seconds;
}