Raised This Month: $ Target: $400
 0% 

[STOCK] DateToTimeStamp converter


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 02-27-2013 , 12:24   [STOCK] DateToTimeStamp converter
Reply With Quote #1

provides stock to convert a date to seconds since Unix Epoch (01.01.1970)

attached test plugin
command to test "date_test" - only from server console or rcon

PHP Code:
stock DateToTimeStamp(daymonthyearhourminuteseconds)
{
    return 
YearToSeconds(year) + MonthToSeconds(yearmonth) + DaysToSeconds(day) + TimeToSeconds(hourminuteseconds) - 21600// Why it returns more by 21600?
}

stock YearToSeconds(year)
{
    new 
var1 year 4;
    new 
var2 year var1;
    
    new 
var3 var1 492;
    new 
var4 var2 1478;
    
    
var3 *= 31622400;
    
var4 *= 31536000;
    
    return 
var3 var4;
}

// 31 days = 2678400 seconds
// 30 days = 2592000
// 29 days = 2505600
// 28 days = 2419200

stock MonthToSeconds(yearmonth)
{
    
month -= 1;
    
    new 
result;
    
    switch (
month)
    {
        case 
1357810 :
        {
            
result 2678400;
        }
        case 
:
        {
            if (
year == 0)
            {
                
result 2505600;
            }
            else
            {
                
result 2419200;
            }
        }
        case 
46911 :
        {
            
result 2592000;
        }
    }
    
    if (
month 1)
    {
        
result += MonthToSeconds(yearmonth);
    }
    
    return 
result;
}

stock DaysToSeconds(days)
{
    
days-=1;
    return 
days 86400;
}

stock TimeToSeconds(hourminuteseconds)
{
    return 
hour 3600 minute 60 seconds;

Attached Files
File Type: inc date.inc (1.1 KB, 263 views)
File Type: sp Get Plugin or Get Source (test.sp - 274 views - 1.3 KB)

Last edited by Despirator; 02-27-2013 at 12:26.
Despirator is offline
 


Thread Tools
Display Modes

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 18:29.


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