Results 1 to 4 of 4

Thread: Days in 2 Dates

  1. #1

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Question Days in 2 Dates

    Hello,

    I have 2 dates lets say: 1-1-2005 and 5-1-2005. Now there are 5 days in those dates. I want to get the days from the 2 specified days.

    How do i do that ? Please help.

    Thanks.
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

  2. #2

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Re: Days in 2 Dates

    Hi,

    I was trying this query but it does not seems to be working and i am getting an error instead:

    $q3 = "SELECT DATEDIFF ('" . $a1["sdate"] . " 23:59:59', '" . $a1["fdate"] . "')";
    $r3 = mysql_query($q3) or die(mysql_error());
    echo mysql_result($r3, 0);


    The error i am getting is:

    You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '('2005-05-10 23:59:59', '2005-06-18')' at line 1

    Please help.

    Thanks
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Days in 2 Dates

    Quote Originally Posted by AvisSoft
    Hello,

    I have 2 dates lets say: 1-1-2005 and 5-1-2005. Now there are 5 days in those dates. I want to get the days from the 2 specified days.

    How do i do that ? Please help.

    Thanks.
    Manavo11 gave you a link in this thread which shows you exactly how to do this.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Re: Days in 2 Dates

    Hi,

    Thanks for that code..but i got around with that using the following code. Here it is maybe it will help others also who don't wanna get involved in mysql:

    PHP Code:
                    $sVar_dateString1 $a1["sdate"];
                    
    $sVar_dateString2 $a1["fdate"];

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

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

                    
    $iVar_timeDifference $iVar_time2 $iVar_time1;
                    
    $iVar_dayDifference = ($iVar_timeDifference / (60 60 24)) + 1;
                    echo 
    $iVar_dayDifference
    Thanks
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

Posting Permissions

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



Click Here to Expand Forum to Full Width