Is it possible to check difference between days in SAMP?
#1

Lets say I have a house system that keeps track of "lasttimeownerenter" and that date is

2.1.2013

And today is the 18.1.2013.

Is it possible to check the difference in days of those two days? Should I just get todays date, and the last enter and do

18-2? Or is there a better way?

If I'd use mysql or sqlite I'd just do DATEDIFF but I use y_ini.
Reply
#2

Take a look at unix timestamps.
Reply
#3

I read over it, my current problem is how to convert my date to the unix timestamp. Lets set a different example, I have:

LastLogin = 12/1/2013

How would I go ahead to turn it to a unix timestamp? From that point I'd probably be able to make the rest.
Reply
#4

You just need to make LastLogin an integer, I'm pretty sure in that thread there's a function to calculate the date (as a unix timestamp) and the difference between two of them (with unix timestamps).

You essentially would make LastLogin the current date as a unix timestamp, then you can just use a simple compare operator between the two dates, but there's also a function in there which returns the amount of days/minutes/seconds since the two dates.
Reply
#5

Alrighty, got this far. Stored 1326844800 in LastLogin which is year and used the function from the thread. Its showing me whats the difference and it seems correct. Now just to figure out how to make it so it warns or something when the difference is over 15 days.

Actually I'm not so sure.
Changed lastlogin to this value: 1358208000 which is 15 jan 2013. However getdifference shows me the following: 17 days.

pawn Code:
CMD:getdifference(playerid, params[])
{
    new iRandomTime = PlayerData[playerid][pLastLogin]-1209600; // Now minus 24 hours and 2 seconds, for the sake of this example
    new szMessage[64];

    format(szMessage, sizeof(szMessage), "It has been: %s", timec(iRandomTime)); // Format our message, saying how long it has been since 'iRandomTime'
    SendClientMessage(playerid, COLOR_ORANGERED, szMessage); // Print our string
   
    if(
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)