Raised This Month: $ Target: $400
 0% 

Stock: IsDateInPast


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 03-09-2012 , 23:29   Stock: IsDateInPast
Reply With Quote #1

I just wrote this stock for an upcoming thing I'm about to release (I love the feeling when you're so close to releasing a big project you can taste it! ).

It accepts a single parameter, a date string formatted as YYYY-MM-DD, and compare it to the current server date. If the date is in the past, it returns true. Otherwise, it returns false (also returns false if the dates are identical).

I haven't tested it yet, but it should work fine. Let me know if there's a problem with it.

PHP Code:
stock bool:IsDateInPast(const String:date[]) {
    
decl String:curYear[4], String:curMonth[2], String:curDay[2], String:oldDate[3][4];
    
FormatTime(curYearsizeof(curYear), "Y");
    
FormatTime(curMonthsizeof(curMonth), "m");
    
FormatTime(curDaysizeof(curDay), "d");
    
ExplodeString(date"-"oldDate34);
    new 
cy StringToInt(curYear);
    new 
cm StringToInt(curMonth);
    new 
cd StringToInt(curDay);
    new 
oy StringToInt(oldDate[0]);
    new 
om StringToInt(oldDate[1]);
    new 
od StringToInt(oldDate[2]);
    if(
oy cy) {
        return 
true// the year we're comparing to is less than the current, it's in the past
    
}
    if(
oy cy) {
        return 
false// the year we're comparing to is greater than the current, it's in the future
    
}
    
// at this point the years must be identical
    
if(om cm) {
        return 
true// the month we're comparing to is less than the current, it's in the past
    
}
    if(
om cm) {
        return 
false// you get the drift
    
}
    
// at this point the months must be identical
    
if(od cd) {
        return 
true;
    }
    if(
od cd) {
        return 
false;
    }
    
// at this point the days are identical
    // identical days is not the past, so return false
    
return false;

__________________
Dr. McKay is offline
 



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:38.


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