MySQL / DATE_FORMAT
#1

Hello guys, I'm experiencing a small problem.
I'm using mysql r39-2 plugin.
When a player logs onto his account I send a query to update their last login time

pawn Код:
mysql_format(MC, query, sizeof(query), "UPDATE players SET IP = '%s', LastLogin = NOW() WHERE Name = '%s'", PlayerIP[playerid], Name[playerid]);
        mysql_tquery(MC, query);
The type of the field in the database is datetime so it looks like
Код:
2015-03-17 17:00:03
As I want to return ingame in this format: March 17, 2015 17:00:03 I tried to use the date_format function, but I'm not sure how to take the result and send it as a message ingame.
So far I did this:

pawn Код:
mysql_query(MC, "SELECT DATE_FORMAT( 'LastLogin' , '%%M %%d %%Y %%h:%%i:%%s' ) AS `LastLogin` FROM `players` WHERE `Name` = '%s' LIMIT 1", Name[playerid]);
So I need help about how to take the result and send it. So instead of:
Код:
Welcome back, your last login was on 2015-03-17 17:00:03
It will be:
Код:
Welcome, back your last login was on March 17 2015 17:00:03
Thanks in advance.
Reply
#2

try this (credits to ***** for the plugin)
https://github.com/Y-Less/sscanf/wiki/%22p%22-Specifier
i cant really give a tutorial about it (i didnt use it much) but basically thats what u need

edit:
like this mayb?
sscanf(variable_name,"p<-:>dddddd",yy,mm,dd,hour,min,sec)
Reply
#3

You can just change the format to text. That's what I do with dates. Then I load/save them like any other string.
Reply
#4

just get content normal(cache_get_field_content)
Reply
#5

Quote:
Originally Posted by rickisme
Посмотреть сообщение
just get content normal(cache_get_field_content)
And how will I convert the date ?
Reply
#6

Isn't that what DATE_FORMAT() already does? Just fetch it as string and display it as string. How hard could it possibly be?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)