Results 1 to 4 of 4

Thread: MySQL Statement

  1. #1

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

    Unhappy MySQL Statement

    Hello,

    I have 2 date fields in a sql table i.e: StartDate and EndDate. I get 2 dates from user those are also StartDate and EndDate. Now i have to make 3-4 queries so that i can check if the user specified dates are not in collision with dates in DB.

    1. If StartDate = StartDate (i have got this)
    2. If EndDate = EndDate (i have got this)

    3. If StartDate is in between the date range of db's StartDate or EndDate
    Means if there is date like: 1-1-2005 and 5-1-2005 in db. And if user StartDate is 4-1-2005 then it should tell me that it exists.

    4. Same as 3 for End Date if EndDate is between the DB's date range then i should get message saying it exists.

    For now i think only want these 2 which i am unable to find how will i do it. If there is some php function in whcih i can check if the StartDate is in between 2 specified dates or equal to them then it will save me one hell of a time.

    Please help too urgnt.

    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

    Angry Re: MySQL Statement

    Hi,

    I cooked up a bit of code but i think i am not gettig anywhere:

    PHP Code:
    $q1 "SELECT * FROM reservations WHERE '$startd' >= sdate AND '$startd' =< fdate";
    $r1 mysql_query($q1) or die(mysql_error());
    $rows mysql_num_rows($r1); 
    Please help.
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: MySQL Statement



    Has someone helped you? Then you can Rate their helpful post.

  4. #4

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

    Re: MySQL Statement

    Hi,

    I got it working by the following code:

    PHP Code:
    $q1 "SELECT * FROM reservations WHERE
            UNIX_TIMESTAMP('
    $startd') >= UNIX_TIMESTAMP(sdate) AND
            UNIX_TIMESTAMP('
    $startd') <= UNIX_TIMESTAMP(fdate)"
    Thanks anyways.
    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