[HELP] convert unix timestamp to d,m,y format
#1

Hello is there a way when I showing in text when is player last logged in to show in format 10/10/2014. Know I have in mysql format like 2014-10-10 so is there a way to convert this in format above this text and to show that format to admins when they check offline player last activity ? Thanks
Reply
#2

Are you meaning in game? (scriptwise)?
Reply
#3

yes I want to convert unixtimestamp from format 2014-10-10 to format 10/10/2014. Thanks
Reply
#4

Could you show me the code where you have the date being set?
Reply
#5

if you know anything about mysql then you should know that is timestamp automatic set date and time into player column it's not in script. Anyway thanks for replying.
Reply
#6

https://sampwiki.blast.hk/wiki/Getdate

Quote:
Originally Posted by SA-MP Wiki
pawn Код:
new Year, Month, Day;
getdate(Year, Month, Day);
printf("%02d/%02d/%d", Day, Month, Year);
Reply
#7

Sorry, have you tried this?
http://www.w3schools.com/sql/func_date_format.asp
Reply
#8

So I was put under onplayerdisconnect

pawn Код:
new str[128],Year,Month,Day;
    getdate(Year,Month,Day);
    format(str,128,"%d/%d/%d",Day,Month,Year);
and then

pawn Код:
mysql_format(mysql,query,sizeof(query),"UPDATE `users` SET `LastActivity` = %s WHERE `ID` = '%d'",str,PlayerInfo[playerid][ID]);
        mysql_tquery(mysql,query,"","");
LastActivity column  is set to varchar which is string
and when I enter in server and disconnect the result in player column LastActivity was 0.000496524329692154
Reply
#9

then you can do something like :
pawn Код:
mysql_format(mysql,query,sizeof(query),"UPDATE `users` SET `LastActivityDay` = %d,`LastActivityMonth` = '%d',
`LastActivityYear`='%d' WHERE `ID` = '%d'"
,Day,Month,Year,PlayerInfo[playerid][ID]);
        mysql_tquery(mysql,query,"","");
you have to add LastActivityYear,LastActivityDay,LastActivityMonth to the mysql and when you load it:
PlayerInfo[playerid][LastActivityYear],PlayerInfo[playerid][LastActivityDay],
PlayerInfo[playerid][LastActivityMonth] and you have to add LastActivityYear,LastActivityMonth,LastActivityDay to the player info enums

so example of loading:
pawn Код:
new str[120];
format(str,120,"Your last activity: %d/%d/%d",PlayerInfo[playerid][LastActivityDay],PlayerInfo[playerid][LastActivityMonth],PlayerInfo[playerid][LastActivityYear]);
SendClientMessage(playerid,-1,str);
Reply
#10

anyone? thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)