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

[SQL] Select CURDATE and format it


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zack771
Senior Member
Join Date: Apr 2012
Old 06-17-2014 , 13:20   [SQL] Select CURDATE and format it
Reply With Quote #1

Hi,

In one of my plugin i need to select current date, so i've made a SQL_Query(db,"SELECT CURDATE()+0") to fetch a number.

What i want is to get the actual day and the SQL value return a date in the format AAAADDMM so in order to get the DD i've try this, can you tell me if it's good or wrong (if it's wrong what does i need to do please) ?

PHP Code:
new dateInt SQL_FetchInt(hQuery,0); //initial fetch value from the SQL_Query
new Float:dateFloat float(dateInt)/10000.0;
new 
Float:dateFloat2 FloatFraction(dateFloat);
new 
Float:dateFloatFin RoundToFloor(dateFloat2/100.0);
if(
dateFloatFin==1) { //if it's the first day of the month
//some stuff

Thanks by advance
__________________
"Embrace your dreams, and whatever happend protect your honor"
Zack Fair
Zack771 is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 06-17-2014 , 14:06   Re: [SQL] Select CURDATE and format it
Reply With Quote #2

Your code is completely insane, I'll therefore skip the suggestions.
This should be what you want
PHP Code:
SELECT DATE_FORMAT(CURRENT_DATE(), '%Y%d%m'currentDate 
If you just want the current day of the month, this should do
PHP Code:
SELECT DAY(CURRENT_DATE()) AS currentDay 
I just want to remind you that you don't really have to use your database to get the current day.

This is one way to get the current day in sourcepawn
PHP Code:
decl String:sTime[3];
FormatTime(sTimesizeof(sTime), "%d");
new 
currentDay StringToInt(sTime); 
__________________

Last edited by Impact123; 06-17-2014 at 14:19.
Impact123 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-17-2014 , 17:28   Re: [SQL] Select CURDATE and format it
Reply With Quote #3

...you are aware that SourceMod has a GetTime() function to return the current UNIX timestamp and a FormatTime timestamps look nice and pretty?

As a reminder, UNIX timestamps have no timezone information and are just the number of seconds since January 1, 1970 00:00:00 UTC. If you're getting the wrong timestamps back from your server, adjust cfg/sourcemod/sourcemod.cfg's sm_time_adjustment cvar.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-17-2014 at 17:33.
Powerlord is offline
Zack771
Senior Member
Join Date: Apr 2012
Old 06-18-2014 , 05:26   Re: [SQL] Select CURDATE and format it
Reply With Quote #4

Quote:
Originally Posted by Impact123 View Post
Your code is completely insane, I'll therefore skip the suggestions.
This should be what you want
PHP Code:
SELECT DATE_FORMAT(CURRENT_DATE(), '%Y%d%m'currentDate 
If you just want the current day of the month, this should do
PHP Code:
SELECT DAY(CURRENT_DATE()) AS currentDay 
I just want to remind you that you don't really have to use your database to get the current day.

This is one way to get the current day in sourcepawn
PHP Code:
decl String:sTime[3];
FormatTime(sTimesizeof(sTime), "%d");
new 
currentDay StringToInt(sTime); 
Yeah i know it's insane, it's why i'm asking here for suggestions ^^'

Thanks you for SQL query, i did not know that those "functions" exist.

For the FormatTime function, i think you forgot to add GetTime() :
PHP Code:
FormatTime(sTimesizeof(sTime), "%d"); 
should be :
PHP Code:
FormatTime(sTimesizeof(sTime), "%d",GetTime()); 
?
Quote:
Originally Posted by Powerlord View Post
...you are aware that SourceMod has a GetTime() function to return the current UNIX timestamp and a FormatTime timestamps look nice and pretty?

As a reminder, UNIX timestamps have no timezone information and are just the number of seconds since January 1, 1970 00:00:00 UTC. If you're getting the wrong timestamps back from your server, adjust cfg/sourcemod/sourcemod.cfg's sm_time_adjustment cvar.
I know the GetTime() function but not FormatTime.
Thanks i'm gonna use the sourcemod way (like Impact123 show it).
__________________
"Embrace your dreams, and whatever happend protect your honor"
Zack Fair

Last edited by Zack771; 06-18-2014 at 05:54.
Zack771 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-18-2014 , 09:08   Re: [SQL] Select CURDATE and format it
Reply With Quote #5

Quote:
Originally Posted by Zack771 View Post
For the FormatTime function, i think you forgot to add GetTime() :
PHP Code:
FormatTime(sTimesizeof(sTime), "%d"); 
should be :
PHP Code:
FormatTime(sTimesizeof(sTime), "%d",GetTime()); 
?
The timestamp argument is optional and the current timestamp is used if you don't provide one.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Zack771
Senior Member
Join Date: Apr 2012
Old 06-18-2014 , 14:34   Re: [SQL] Select CURDATE and format it
Reply With Quote #6

Quote:
Originally Posted by Powerlord View Post
The timestamp argument is optional and the current timestamp is used if you don't provide one.
Ok thanks for help
__________________
"Embrace your dreams, and whatever happend protect your honor"
Zack Fair
Zack771 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 11:45.


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