Raised This Month: $51 Target: $400
 12% 

Solved Precise calculation between 2 dates and times in UnixTimestamp


Post New Thread Reply   
 
Thread Tools Display Modes
Natsheh
Veteran Member
Join Date: Sep 2012
Old 06-24-2021 , 02:14   Re: Precise calculation between 2 dates and times in UnixTimestamp
Reply With Quote #11

Bugsy the format you made it converts only weeks in numbers i think he wants to be able also to convert weeks in thier name form.

I can make you a simple stock so it can format any type of time formats but you need to wait until i come back to home.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 06-24-2021 at 02:19.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-24-2021 , 09:42   Re: Precise calculation between 2 dates and times in UnixTimestamp
Reply With Quote #12

Quote:
Originally Posted by Natsheh View Post
Bugsy the format you made it converts only weeks in numbers i think he wants to be able also to convert weeks in thier name form.

I can make you a simple stock so it can format any type of time formats but you need to wait until i come back to home.
I can easily do that too, but I don't think your assumption is true. He is retrieving the weekday name using get_time( "%A" ) and then passing that to CalculateDays(const szDay[]) to get the numerical day-of-week value, he should have instead used "%w", as my code does, as it eliminates the need for his CalculateDays() function.
Code:
%A	Full weekday name *	Thursday
%w	Weekday as a decimal number with Sunday as 0 (0-6)	4
This is why I asked for a verbal explanation as without a specific use-case, we have to make assumptions. He advised to refer to post 3, which is what I based my code off of:

"Thanks for taking the time to respond, the "problem" is that I want this automated function to run on a specific day and time every week, for example every Saturday 12 PM, which is why parse_time doesn't seem to cover this situation."

Code:
public CalculateStrings() {         new Time[15], ToDay[5],  Month[5]
        //%A - Full weekday name *  Thursday
        get_time("%A", Time, charsmax(Time))
        new EventDay = 7 - CalculateDays(Time)
        get_time("%d", ToDay, charsmax(ToDay))         new iFutureDate = str_to_num(ToDay) + EventDay         get_time("%m", Month, charsmax(Month))         new FormatedFutureDate[30]         formatex(FormatedFutureDate, charsmax(FormatedFutureDate), "19:00:00 %i/%i/2021", str_to_num(Month), iFutureDate)         new iFutureDateTime = parse_time( FormatedFutureDate , "%H:%M:%S %m/%d/%Y" );         new iCurrentDateTime = get_systime();         Counter = iFutureDateTime - iCurrentDateTime;         set_task_ex(1.0, "TimeToEvent", TASK_HUD_DROP, .flags = SetTask_Repeat) } convert_seconds( iTotalSeconds , &seconds , &minutes , &hours , &days ) {         days = iTotalSeconds / 86400         hours = ( iTotalSeconds / 3600 ) % 24         minutes = ( iTotalSeconds / 60 ) % 60         seconds = iTotalSeconds % 60 } 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
}
__________________

Last edited by Bugsy; 06-24-2021 at 09:59.
Bugsy is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 06-24-2021 , 16:51   Re: Precise calculation between 2 dates and times in UnixTimestamp
Reply With Quote #13

Bugsy correctly understood the need, to be honest I didn't see the option to use %w, which is why I created the stock, thank you very much for your help.
__________________


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/
iceeedr is offline
Send a message via Skype™ to iceeedr
buracat
New Member
Join Date: Feb 2016
Old 02-17-2024 , 18:16   Re: Precise calculation between 2 dates and times in UnixTimestamp
Reply With Quote #14

Quote:
Originally Posted by Bugsy View Post
Ok, it's a lot simpler then if I understand correctly. format_time() can do most of the work for you, see http://cplusplus.com/reference/ctime/strftime/

PHP Code:

#include <amxmodx>

enum _:WeekDays
{
    
wdSunday,
    
wdMonday,
    
wdTuesday,
    
wdWednesday,
    
wdThursday,
    
wdFriday,
    
wdSaturday
}

enum _:TimeStringPos
{
    
tspDayOfWeek,
    
tspSpace,
    
tspHour
}

public 
plugin_init() 
{
    new 
szOutput] , iDayOfWeek iHour;

    
//1624465533 = Wed Jun 23 2021 12:25:33 GMT-0400 (Eastern Daylight Time)
    
format_timeszOutput charsmaxszOutput ) , "%w %H" 1624465533 );
    
    
szOutputtspSpace ] = EOS;
    
iDayOfWeek str_to_numszOutputtspDayOfWeek ] );
    
iHour str_to_numszOutputtspHour ] );
    
    if ( ( 
iDayOfWeek == wdWednesday ) && ( iHour == 12 ) )
    {
        
server_print"It is Wednesday at 12pm" );
    }

Hi, How did this number come about? -> "1624465533"
buracat is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-17-2024 , 18:21   Re: Precise calculation between 2 dates and times in UnixTimestamp
Reply With Quote #15

Quote:
Originally Posted by buracat View Post
Hi, How did this number come about? -> "1624465533"
That’s just an example Unix/epoch timestamp, I assume you know what they are/how they work. Any date/time post 1/1/1970 can be converted to an integer value, down to the second. This is the type of value that get_systime() returns and what nVault timestamps represent.

https://www.epochconverter.com/
__________________

Last edited by Bugsy; 02-17-2024 at 22:45.
Bugsy is offline
Reply



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 14:19.


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