Forum Moderators: coopster

Message Too Old, No Replies

Help with this code

second day= the entered day +1

         

Yangtze

5:00 am on Mar 28, 2004 (gmt 0)

10+ Year Member



Does anyone happen to know a similar calendar like the Holiday Inn's?
[ichotelsgroup.com...]

When you select, say March 1, 2004 for the check-in date, the check-out date will be immidately changed to March 2, 2004, without the need to use the calendar again.

Thanks.

---------
I was searching online during the past week with the hope to find the solution by myself, but failed.

So I turned to webmasterworld.com.

Yangtze

5:04 am on Mar 28, 2004 (gmt 0)

10+ Year Member



Someone told me that I would use this dateadd, but I'm not sure how to do that.

I tried strftime
A friend offered me the code:

$checkindate = explode("-", $checkindate);
list($year, $month, $day) = $checkindate;
$checkoutdate = strftime("%Y-%m-%d", mktime(0,0,0,$month,$day+$nights,$year)); //$nights being the interval
echo "begin date $checkindate to $checkoutdate";

Confused!

[edited by: Yangtze at 5:31 am (utc) on Mar. 28, 2004]

Timotheos

5:26 am on Mar 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The Holiday Inn calander is using javascript. Just view the source and you can see how it's done.

Yangtze

5:30 am on Mar 28, 2004 (gmt 0)

10+ Year Member



Can I do this by PHP?

Someone told me to use "dateadd"

WhosAWhata

7:26 am on Mar 28, 2004 (gmt 0)

10+ Year Member



there is a huge difference between javascript and php
JavaScript is a client side scripting language, so it is possible to make things like dynamic calendars without loading the page.
PHP is a server side scripting lanuage, so to make any change on the screen using only php, you need to refresh

as for changing your date, look into date() functions on PHP's Date manual [php.net]

coopster

12:30 am on Mar 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Hi Yangtze, I seen your related thread, The second datetime is default 4 days later [webmasterworld.com], earlier but didn't have a chance to respond. DATE_ADD [mysql.com] is a MySQL function, used something like this:
INSERT INTO your_table 
(checkindate, checkoutdate)
VALUES('2004-03-28', DATE_ADD(checkindate, INTERVAL 4 DAY))
;

There is a related javascript solution found here at WebmasterWorld:
DATE_ADD with JavaScript [webmasterworld.com]

coopster

1:32 pm on Mar 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yangtze wrote:

You suggested:
INSERT INTO your_table (checkindate, checkoutdate) VALUES('2004-03-28', DATE_ADD(checkindate, INTERVAL 4 DAY))

I'm sorry but may I ask where should I input this set of php code?

And should I check the code to:
INSERT INTO your_table (checkindate, checkoutdate) VALUES('checkindate', DATE_ADD(checkindate, INTERVAL 4 DAY))

This is not PHP code, it is a MySQL query statement. The example I explained was to clarify what the

DATE_ADD
function is in MySQL and how it works (as asked in msg #2).

No, you cannot change the code as you requested, you will end up with a NULL value in your checkindate column as it is not a valid date.

If it were me, I'd ask for a checkindate, validate the date, and then display the checkindate as well as the calculated checkoutdate during "approval" or "verify-your-entries" processing. If you want to show the checkoutdate prior to form submittal, you can use a client-side scripting language such as javascript. In addition, you should calculate and verify the checkoutdate on the server-side prior to processing.

Yangtze

5:55 pm on Mar 30, 2004 (gmt 0)

10+ Year Member



Thanks coopster!

I'm now turning to javascript for this function I desired.