I think that using parse_time we were able to overcome the problem of months with plus or minus days.
PHP Code:
#include <amxmodx>
#define PLUGIN "AlliedTest"
#define VERSION "1.0"
#define AUTHOR "iceeedR"
new g_CvarDate[30]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
bind_pcvar_string(create_cvar("amx_target_time", "09:00:00 11/22/2023"), g_CvarDate, charsmax(g_CvarDate))
}
public plugin_cfg()
CalculateStrings()
public CalculateStrings()
{
new iTargetDateTime = parse_time( g_CvarDate , "%H:%M:%S %m/%d/%Y" )
new iCurrentDateTime = get_systime()
new Counter = iTargetDateTime - iCurrentDateTime
new iSeconds , iMinutes , iHours , iDays
convert_seconds( Counter , iSeconds , iMinutes , iHours , iDays );
if(Counter > 0)
{
if(iDays)
{
server_print("Time to day %s: %d day(s) and %d Hour(s)", g_CvarDate, iDays, iHours)
return PLUGIN_HANDLED
}
server_print("Time to day %s: %d:%d:%d", g_CvarDate, iHours, iMinutes, iSeconds)
return PLUGIN_HANDLED
}
else
{
server_print("Has passed: %d day(s) %d Hour(s) %d Minute(s) and %d Second(s) until %s", iDays *= -1, iHours, iMinutes, iSeconds, g_CvarDate)
return PLUGIN_HANDLED
}
}
convert_seconds( iTotalSeconds , &seconds , &minutes , &hours , &days )
{
days = iTotalSeconds / 86400
hours = ( iTotalSeconds / 3600 ) % 24
minutes = ( iTotalSeconds / 60 ) % 60
seconds = iTotalSeconds % 60
}
It is also possible to get the time elapsed from the date.
HTML Code:
Time to day 09:00:00 11/22/2023: 388 day(s) e 19 Hour(s)
Has passed: 4 day(s) 3 Hour(s) 49 Minute(s) and 46 Second(s) until 18:00:00 10/25/2022
__________________