Timestamp problems [REP+]
#1

Hey guys, I have some problems with timestamps:
I use to send an update query with unix timestamp, when player logs in to his account and show a message with the last time on, the message looks like:
Welcome back, Wizzy951! Your last login was on 2013-11-28 03:22:15.
I would want the message look like:
Welcome blabla on November 28, 2013 at 03:22:15, Also if the last login was on the same day to show Today, at 03:22:15

And there is my code:
pawn Код:
#define pLastLoginx 1 //it's used for the update query, I got this from a gamemode from the forums, I don't really remember whose it was

pLastLogin[130]//this stays within the enumerator

//on loading player stats
cache_get_field_content(0, "LastLogin", tmp),   strmid(PInfo[playerid][pLastLogin], tmp, 0, 255, 255);
Update(playerid, pLastLoginx);
format(string, sizeof(string), "Welcome back, %s! Your last login was on %s", rName(playerid), PInfo[playerid][pLastLogin]);
SendClientMessage(playerid, -1, string);

//the update function which I got from the gamemode I mentioned before
public Update(playerid, type)
{
    if(IsPlayerConnected(playerid))
    {
        new query[256];
        {
            switch(type)
            {
                case pLastLoginx:
                {
                    format(query, sizeof(query), "UPDATE players SET LastLogin = NOW() WHERE Name = '%s' LIMIT 0,1", rName(playerid));
                    mysql_query(Db, query);
                }
            }
        }
    }
}
The second problem is related with the database structure and I'm not even sure if I have to ask there, but still I believe someone could help me: I had wanted to use timestamp also when player registers so I added a new line called ReggedOn with type: timestamp without setting anything else and I received the following error:
#1293 - Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

Thanks in advance!
Edit: Rep only to the useful replies!
Reply
#2

-Edited-
Reply
#3

There is also datetime for NOW() in table structure but is a string i think
Reply
#4

Quote:
Originally Posted by iJumbo
Посмотреть сообщение
There is also datetime for NOW() in table structure but is a string i think
The table structure isn't actually the main problem.
Reply
#5

tmp is from the first cache_get_field_content(0, "LastLogin", tmp)
pawn Код:
format(str,sizeof(str),"SELECT DATE_FORMAT( '%s' , '%M %d %Y %h:%i:%s' ) AS LastLogin;",tmp);
query_here
cache_get_field_content(0, "LastLogin", tmp);
should returns "November 29 2013 01:06:37"

http://dev.mysql.com/doc/refman/5.5/...on_date-format
Reply
#6

Quote:
Originally Posted by Jefff
Посмотреть сообщение
tmp is from the first cache_get_field_content(0, "LastLogin", tmp)
pawn Код:
format(str,sizeof(str),"SELECT DATE_FORMAT( '%s' , '%M %d %Y %h:%i:%s' ) AS LastLogin;",tmp);
query_here
cache_get_field_content(0, "LastLogin", tmp);
should returns "November 29 2013 01:06:37"

http://dev.mysql.com/doc/refman/5.5/...on_date-format
Well it seems to work, but I can't get what happened with PInfo[playerid][pLastLogin] ? Or actually which placeholder should I use to show in the message ?
Reply
#7

You don't need this in this case ( PInfo[playerid][pLastLogin] )

next

use sscanf to separate and compare day

pawn Код:
sscanf(tmp,"s[15]i{i}s[9]",lastMonth,lastDay,lastTime);
getdate(...);
pawn Код:
if(CurrentDay == lastDay)
format(str,sizeof(str),"Welcome blabla on Today, at %s",lastTime);
else
format(str,sizeof(str),"Welcome blabla on %s %d, %d at %s",lastMonth,lastDay,year_from_getdate,lastTime);

SendClientMessage(...);
you can compare month names too
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)