This topic is locked
[SOLVED]

 Display Amount Of Nights From 2 Fields

6/27/2013 3:06:05 PM
PHPRunner General questions
S
scoobysteve author

Hi in PHPR6.2 I want to display in a read only format the amount of days based on 2 other fields.
[ArrivalDate]

[DepartureDate]
And the field I want the days to appear in are
[NumberOfNights]
I want to be able enter the [ArrivalDate] and [DepartureDate] in the Add/Edit views and have the results appear in the List page.
If you can help I would appreciate it.
Thanks in advance

Steve

C
cgphp 6/27/2013

Set the field on the List page as Custom and enter the following code:

$arrival = strtomtime($data['ArrivalDate']);

$departure = strtotime($data['DepartureDate']);

$value = ($departure - $arrival) / (3600 * 24);
S
scoobysteve author 6/27/2013



Set the field on the List page as Custom and enter the following code:

$arrival = strtomtime($data['ArrivalDate']);

$departure = strtotime($data['DepartureDate']);

$value = ($departure - $arrival) / (3600 * 24);



Thanks Cristian but I get the following error on with this code, any ideas.
Thanks Steve
Fatal error: Call to undefined function strtomtime() in D:\Sites\mywebsite.co.uk\public_html\bookings\include\phpfunctions.php on line 625

C
cgphp 6/27/2013

Sorry, a typing error. Try this code:

$arrival = strtotime($data['ArrivalDate']);

$departure = strtotime($data['DepartureDate']);

$value = ($departure - $arrival) / (3600 * 24);
S
scoobysteve author 6/27/2013



Sorry, a typing error. Try this code:

$arrival = strtotime($data['ArrivalDate']);

$departure = strtotime($data['DepartureDate']);

$value = ($departure - $arrival) / (3600 * 24);



Thanks Cristian, that fixed it , your a star.
Steve

S
scoobysteve author 6/27/2013



Sorry, a typing error. Try this code:

$arrival = strtotime($data['ArrivalDate']);

$departure = strtotime($data['DepartureDate']);

$value = ($departure - $arrival) / (3600 * 24);



Cristian, could I use this code in a similar way to work out a date 70 days before the ArrivalDate, I tried

the follwoing but I got a long number in the results.
I want to know the date 70 days before the arrival date.
$arrival = strtotime($data['ArrivalDate']);

$value = ($arrival) - (70);
Thanks

Steve

C
cgphp 6/27/2013
$arrival = strtotime($data['ArrivalDate']);

$daysbefore = 3600 * 24 * 70;

$diff = $arrival - $daysbefore;

$value = date("Y-m-d", $diff);
S
scoobysteve author 6/27/2013


$arrival = strtotime($data['ArrivalDate']);

$daysbefore = 3600 * 24 * 70;

$diff = $arrival - $daysbefore;

$value = date("Y-m-d", $diff);



Thank you very much Cristian.
Steve

S
scoobysteve author 6/28/2013



Thanks Cristian, that fixed it , your a star.
Steve


Christian,
I used this and its works fine but today I was doing data entry and on one entry the date is all wrong, I am using the above code and like I said its fine for the other 25 records, I have attached a screen shot so you can see.


Is there anything I can do please.
Regards

Steve

C
cgphp 6/28/2013

The number of nights (7) is correct. You have only to floor the number:

$arrival = strtotime($data['ArrivalDate']);

$departure = strtotime($data['DepartureDate']);

$value = floor(($departure - $arrival) / (3600 * 24));
S
scoobysteve author 6/28/2013



The number of nights (7) is correct. You have only to floor the number:

$arrival = strtotime($data['ArrivalDate']);

$departure = strtotime($data['DepartureDate']);

$value = floor(($departure - $arrival) / (3600 * 24));



Thanks again Cristian, I will try that tomorrow I am sure it will be fine thank you sir.
Steve