SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    564
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question How to differentiate between dates

    Hello,

    I think i am bugging you people alot with dates and am sorry about that. I have now a new problem now besides me:

    Suppose there are 2 dates like: 26-01-2005 and 03-02-2005. How do i come to know how many days are there in each month ? For example the answer for this should be: First Month: 6 days for January and Second Month: 3 days for February.

    But if there are same months then it should give answer for only first month and not second month. So for dates like: 26-01-2005 and 30-01-2005 i should get:

    First Month: 5
    Second Month: 0 (becuase there's no second month)

    I hope that i am correctly explained my problem.

    Thanks

  2. #2
    SitePoint Zealot shaman's Avatar
    Join Date
    Feb 2005
    Location
    W.R. Home
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    get the timestamp as you've stadyied at the another thread, and then look to manual about date("t", $time)
    She's my german fraulein

  3. #3
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    564
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question

    Hi,

    I tried:

    PHP Code:
    echo date("t"UNIX_TIMESTAMP($a1['sdate']));
    echo 
    date("t"UNIX_TIMESTAMP($a1['fdate'])); 
    But i get error:

    Fatal error: Call to undefined function: unix_timestamp() in /home/avissoft/public_html/olr/cart.php on line 49
    Please help.

    Thanks

  4. #4
    SitePoint Zealot shaman's Avatar
    Join Date
    Feb 2005
    Location
    W.R. Home
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ufhs..... UNIX_TIMESTAMP().... did you try to call the sql function into a php script?

    is $al['sdate'] a date taked from database? if yes, look to your previouse thread and take the time from this data. then use date("t", $time )
    She's my german fraulein

  5. #5
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I haven't fully tested this. But it seems to do the job.

    PHP Code:
    //Assumption made:
    //The months are consecutive
    $iVar_dayDifference1 0;
    $iVar_dayDifference2 0;

    $sVar_dateString1 '2-2-2005';
    $sVar_dateString2 '5-3-2005';

    $aVar_date1 explode('-'$sVar_dateString1);
    $aVar_date2 explode('-'$sVar_dateString2);

    $iVar_time1 mktime(0,0,0,$aVar_date1[1],$aVar_date1[0], $aVar_date1[2]);
    $iVar_time2 mktime(0,0,0,$aVar_date2[1],$aVar_date2[0], $aVar_date2[2]);

    if (
    $aVar_date1[1] == $aVar_date2[1]) {
        
    $iVar_timeDifference $iVar_time2 $iVar_time1;
        
    $iVar_dayDifference1 = ($iVar_timeDifference / (60 60 24)) + 1;
        echo 
    $iVar_dayDifference1;    
        }
    else {
        
    $iVar_time1End mktime(0,0,0,$aVar_date1[1] + 10$aVar_date1[2]);
        
    $iVar_time2Start mktime(0,0,0,$aVar_date2[1], +1$aVar_date2[2]);
        
    $iVar_timeDifference1 $iVar_time1End $iVar_time1;
        
    $iVar_dayDifference1 = ($iVar_timeDifference1 / (60 60 24)) + 1;
        
    $iVar_timeDifference2 $iVar_time2 $iVar_time2Start;
        
    $iVar_dayDifference2 = ($iVar_timeDifference2 / (60 60 24)) + 1;
        echo 
    $iVar_dayDifference1;
        echo 
    '<br>';
        echo 
    $iVar_dayDifference2;
        } 
    Hope that helps.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •