Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking days between session dates 1

Status
Not open for further replies.

sipps

Technical User
Feb 9, 2003
133
GB
Hi all,

I have some session variables that the user inputs into the system, Pick_Up_Day, Pick_Up_Month, Pick_Up_Year, Drop_Off_Day, Drop_Off_Month, Drop_Off_Year. I want to calculate the difference between these dates, and then multiply this value by a rate held in a table in MySQL. I'm not quite sure how to do this, could anyone help?

Thanks
 
Just some questions

1)Are you saying there are 6 session variables????
2)Are these variables passed into a database
3)Why didn't you have just 2 session variables pickup_date and dropoff_date

 
Hi,

The user inputs the day, month and year for picking up a vehicle and dropping off a vehicle, so yes I have 6 session variables to hold all this data. Do you think that I could just have two session variables that take this data from the form and almagamate it into one?

$HTTP_SESSSION_VARS[Pick_Up_Date = $_POST[Pick_Up_Day], $_POST[Pick_Up_month]... etc?

Thanks
 
Sorry I think you have misunderstood what I am getting at in relation to the 2 session variables.

As I understand it you have 3 session variables for pick up.
In Pick_Up_Day, you may enter 12
In Pick_Up_Month, you may enter 01
In Pick_Up_Year, you may enter 2003

Why not replace it with one session variable called Pick_Up_Date, and you would enter 12/01/2003

MySQL can calculate date differences for you, for example the number of days between 2 dates.
 
Yes that is true, I have three session variables for pick up, and three for drop off.

How can I assign three form fields to one session variable then? The user cannot type in the date as you suggest 12/01/2003, they choose from three drop down lists of day, month and then year.

This was my point in how it would be possible to enter many form variables into one session variable, do you know if this is possible?

Thanks
 
try something like the following

$Pick_Up_Date=$Pick_Up_Day."/".$Pick_Up_Month."/".$Pick_Up_Year

You will have to manipulate it slightly to into account that the variables are session variables
 
That worked great, thanks, I now have one session variable for pick up and one for drop off.

I want to use these dates to get the number of days bewtween them, and then multiply this value by Daily_Rental_Amount, can this be done by MySQL or does this have to be done by PHP?

I know how to work out the difference in days, but I am not aware of how to multiply this value by another attribute in the database.

Thanks
 
try something like the following

select ((to_days(date1)-to_days(date2))*field_multiplier) As myvalue from etc. etc.

The field_multiplier is whatever you have called the other field
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top