|
-
May 7th, 2005, 10:54 AM
#1
Thread Starter
Hyperactive Member
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
-
May 7th, 2005, 11:36 AM
#2
Thread Starter
Hyperactive Member
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
-
May 7th, 2005, 02:40 PM
#3
-
May 7th, 2005, 02:48 PM
#4
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|