Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-14-2005, 02:56 AM Compare dates
Raulică's Avatar
Ultra Talker

Posts: 253
Location: Constanta,Romania
Trades: 0
How can i compare 2 dates in "Y-m-d" format ? i tried like this :
PHP Code:
$y date("Y");
$m date("m");
$d date("d");
$i 0;
$ads mysql_query("select cid,cnd from customers");
while(
$row mysql_fetch_array($ads))
{
    
$date $row['cnd'];
    
$cid $row['cid'];
    
$y1 exec("echo $date|cut -d '-' -f 1");
    
$m1 exec("echo $date|cut -d '-' -f 2");
    
$d1 exec("echo $date|cut -d '-' -f 3");
    if((
$d1 == $d) || ($d1 $d))
    {
        if((
$m1 == $m) || ($m1 $m))
        {
            if((
$y1 == $y) || ($y1 $y))
            {
                if(
$k != '1')
                {
                    
show_info($cid);
                    echo 
"" // html tag;
                
}
                else ++
$i;
            }
        }
    }

The function returns the number of my clients instead the number of my clients wich have to pay..
__________________

Please login or register to view this content. Registration is FREE

Professional hosting for all pockets!

Please login or register to view this content. Registration is FREE
Raulică is offline
Reply With Quote
View Public Profile Visit Raulică's homepage!
 
 
Register now for full access!
Old 05-14-2005, 04:56 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
if you have to compare two dates ... why don't you transform them into timestamps?
look into strtotime() .... that way it's much easier to compare them.
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-14-2005, 12:35 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
You can do this in PHP or in SQL before it's parsed back to PHP. If you mean comparing two dates by finding the difference between them (that's what i think you mean) then use this function that returns the days difference between two dates

PHP Code:
function count_days($start$end) {
    if( 
$start != '0000-00-00' and $end != '0000-00-00' ) {
        
$timestamp_start strtotime($start);
        
$timestamp_end strtotime($end);

        if( 
$timestamp_start >= $timestamp_end ) return 0;
        
        
$start_year date("Y",$timestamp_start);
        
$end_year date("Y"$timestamp_end);
        
$num_days_start date("z",strtotime($start));
        
$num_days_end date("z"strtotime($end));
        
$num_days 0;
        
$i 0;
        
            if( 
$end_year $start_year ) {
                while( 
$i < ( $end_year $start_year ) ) {
                    
$num_days $num_days gmdate("z"strtotime(($start_year $i)."-12-31"));
                    
$i++;
                }
            }

        return ( 
$num_days_end $num_days ) - $num_days_start;
    }
    
    else {
        return 
0;
    }

That should work (works fine for me). If you want to know the SQL version, shout up.
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 05-15-2005, 01:44 PM
Raulică's Avatar
Ultra Talker

Posts: 253
Location: Constanta,Romania
Trades: 0
Works fine, thank you verry much !
__________________

Please login or register to view this content. Registration is FREE

Professional hosting for all pockets!

Please login or register to view this content. Registration is FREE
Raulică is offline
Reply With Quote
View Public Profile Visit Raulică's homepage!
 
Reply     « Reply to Compare dates
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.50271 seconds with 12 queries