Raised This Month: $ Target: $400
 0% 

Solved Precise calculation between 2 dates and times in UnixTimestamp


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 06-23-2021 , 13:57   Precise calculation between 2 dates and times in UnixTimestamp
Reply With Quote #1

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(PLUGINVERSIONAUTHOR)

        
// Add your code here...
}

public 
plugin_cfg()
{
        new 
Time[15]
        
get_time("%A"Timecharsmax(Time))

        new 
EventDay 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 
isizeof g_szDaysi++)
        {
                if(
equali(szDayg_szDays[i][szDays]))
                {
                        
Count g_szDays[i][iCount]
                        break
                }
        }

        return 
Count

__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/

Last edited by iceeedr; 06-24-2021 at 16:52.
iceeedr is offline
Send a message via Skype™ to iceeedr
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode