PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 16th, 2012, 04:57 AM
kcachilove kcachilove is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 11 kcachilove User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 46 m 51 sec
Reputation Power: 0
Talking PHP5 - Date comparison issue

Hello, Am a PHP developer , am working a hotel application but the issus am having here maynot be so heard to achive but am stock here and i need your help here.
I have two table which are "blockedrooms" and "bookingstest"

blockedrooms has
blockedrooms (id, id_item, the_date, id_state, id_booking, roomno, hotel_id, entryCode, status, entryDate, blockedby, unblockedby, unblockedDate) VALUES
(16, 1, '2012-11-08', 4, 0, 100, '1', '20121109103253', 0, '2012-11-09 10:32:53', '2', '', '0000-00-00 00:00:00'),
(17, 1, '2012-11-09', 5, 0, 101, '1', '20121109103320', 0, '2012-11-09 10:33:20', '2', '', '0000-00-00 00:00:00'),

bookingstest has

INSERT INTO bookingstest (id, id_item, the_date, id_state, id_booking, roomno, hotel_id, entryCode, status, entryDate) VALUES

(18, 1, '2012-11-08', 5, 0, 101, '1', '20121109103320', 0, '2012-11-09 10:33:20'),
(20, 1, '2012-11-08', 4, 0, 100, '1', '20121109103253', 0, '2012-11-09 15:01:27'),
(21, 1, '2012-11-09', 4, 0, 100, '1', '20121109103253', 0, '2012-11-09 15:02:15'),
(22, 1, '2012-11-09', 5, 0, 101, '1', '20121109103320', 0, '2012-11-09 15:02:15'),
(23, 1, '2012-11-13', 4, 0, 100, '1', '20121109103253', 0, '2012-11-12 13:15:14'),
(24, 1, '2012-11-12', 5, 0, 101, '1', '20121109103320', 0, '2012-11-12 13:15:14'),
(25, 1, '2012-11-15', 4, 0, 100, '1', '20121109103253', 0, '2012-11-15 10:26:39'),
(26, 1, '2012-11-14', 5, 0, 101, '1', '20121109103320', 0, '2012-11-15 10:26:39');

I want to update a bookingstest, but i need to first get the dates that i already have in the bookingstest then compare it with my date range (This date range is the range of dates between a specified Startdate and Enddate) to avoid dupplication in bookingstest and the date range comparesion will start from *the_date* in blockedrooms till today. please how do i achive it i just want to get the dates that are not in bookingstest for each id_state from their start date (2012-11-08 and 2012-11-09) my code for that is below.


$rst=mysql_query("select * from blockedrooms where status=0 order by the_date asc") or die(mysql_error);
//$start = "2012-02-05";
while ($row = mysql_fetch_array($rst,MYSQL_ASSOC)){

$start= $row['the_date'];
$end = date('Y-m-d');
$init_date = strtotime($start);
$dst_date = strtotime($end);

$offset = $dst_date-$init_date;

$dates = floor($offset/60/60/24) + 1;

for ($i = 0; $i < $dates; $i++)
{
$newdate = date("Y-m-d", mktime(12,0,0,date("m", strtotime($start)),
(date("d", strtotime($start)) + $i), date("Y", strtotime($start))));


//echo $rsts['the_date'];
//echo $newdate ."<br>";

$rsts=mysql_query(" select * from bookingstest where the_date IN ('$newdate') and entryCode=".$row['entryCode']." and roomno= ".$row['roomno']." order by roomno asc") or die(mysql_error);
while($rw = mysql_fetch_array($rsts,MYSQL_ASSOC)){
echo $rw['the_date']. ' - '.$rw['roomno']."<br>";

}

}



}

Reply With Quote
  #2  
Old November 16th, 2012, 06:02 AM
rolty's Avatar
rolty rolty is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: UK
Posts: 543 rolty User rank is Sergeant Major (2000 - 5000 Reputation Level)rolty User rank is Sergeant Major (2000 - 5000 Reputation Level)rolty User rank is Sergeant Major (2000 - 5000 Reputation Level)rolty User rank is Sergeant Major (2000 - 5000 Reputation Level)rolty User rank is Sergeant Major (2000 - 5000 Reputation Level)rolty User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 1 h 36 m 49 sec
Reputation Power: 56
It might be easier to get the date range directly from mysql in your initial query with something like:
Code:
"SELECT * FROM blockedrooms
WHERE the_date  BETWEEN '$startdate' AND '$enddate'

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - Date comparison issue

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap