Hi, it's been a while. I've been racking my brain for a few days with a classic XYZ problem, and honestly I ran out of ideas.
I need to calculate the difference between 2 dates and times and return the value to me in unixtimestamp, for example the difference in Unix between now and Friday 14:00PM, but honestly I'm unsuccessful in this.
That's what's left after several attempts, the days return correctly, but I'm in doubt as to how to proceed with the calculation of hours to be an exact value.
PHP Code:
/* Sublime AMXX Editor v2.2 */
#include <amxmodx>
// #include <amxmisc>
// #include <cstrike>
// #include <engine>
// #include <fakemeta>
// #include <hamsandwich>
// #include <fun>
// #include <xs>
// #include <sqlx>
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "Author"
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
// Add your code here...
}
public plugin_cfg()
{
new Time[15]
get_time("%A", Time, charsmax(Time))
new EventDay = 7 - CalculateDays(Time)
Counter = EventDay * 86400
set_task_ex(1.0, "TimeToEvent", TASK_HUD_DROP, .flags = SetTask_Repeat)
}
public TimeToEvent()
{
Counter --
if(Counter > 0)
{
new UnixTimeStamp = Counter
Day = UnixTimeStamp / 86400
UnixTimeStamp = UnixTimeStamp % 86400
Hour = UnixTimeStamp / 3600
UnixTimeStamp = UnixTimeStamp % 3600
Minute = UnixTimeStamp / 60
Second = UnixTimeStamp % 60
if(Day > 1)
{
//
return PLUGIN_HANDLED
}
//
return PLUGIN_HANDLED
}
remove_task(TASK_HUD_DROP)
set_task(0.1, "AnounceEvent")
return PLUGIN_HANDLED
}
CalculateDays(const szDay[])
{
new Count = 0
enum _:ItemData
{
szDays[10],
iCount
}
new const g_szDays[][ItemData] =
{
{"Sunday", 1},
{"Monday", 2},
{"Tuesday", 3},
{"Wednesday", 4},
{"Thursday", 5},
{"Friday", 6},
{"Saturday", 7}
}
for(new i; i < sizeof g_szDays; i++)
{
if(equali(szDay, g_szDays[i][szDays]))
{
Count = g_szDays[i][iCount]
break
}
}
return Count
}
__________________