I'm working on a project and I need to calculate the total amount of hours, given two variables: the start time, and the end time.
So for example, a user would enter 11AM for the start time, and then 2PM for the end time. I can easily do the form, but I am not exactly sure how to get PHP to recognize AM from PM and recognize that the total amount of time is 3 hours. Can anyone help me out a bit?
Thanks.
P.S. It would need to calculate the minutes, also.
I need some development help.
Started by agrtek, Apr 05 2010 08:49 PM
6 replies to this topic
#1
Posted 05 April 2010 - 08:49 PM
|
|
|
#2
Posted 06 April 2010 - 12:10 PM
How is the user entering this data?
#3
Posted 06 April 2010 - 12:18 PM
WingedPanther said:
How is the user entering this data?
It would be through a form, but either way I figured it out.
For future reference, use the strtotime() function and subtract your start and end time. Then take the abs() of the difference and divide it by 3600.
#4
Posted 06 April 2010 - 12:28 PM
If you're using a dropdown, you can have the displayed value be completely different from the transmitted value. There area lot of options.
#5
Posted 06 April 2010 - 01:39 PM
I have another question.
I'm wanting to compare the values of 2 variables to see if they are equal. It involves a timesheets project, and basically I want to compare 1 input field (field A) and see if it is equal to the sum of fields B, C and D together. I can do all of this with PHP but my only problem is I need this to happen on-the-fly, with Ajax or JavaScript. So if field A != (B + C + D) then it will display an error and not let you submit the form, but if A == (B + C +D) then you can submit the form.
Thanks in advance!
I'm wanting to compare the values of 2 variables to see if they are equal. It involves a timesheets project, and basically I want to compare 1 input field (field A) and see if it is equal to the sum of fields B, C and D together. I can do all of this with PHP but my only problem is I need this to happen on-the-fly, with Ajax or JavaScript. So if field A != (B + C + D) then it will display an error and not let you submit the form, but if A == (B + C +D) then you can submit the form.
Thanks in advance!
#6
Posted 09 April 2010 - 12:40 AM
well you could use ajax for that
on the form write onsumbit="return check_sum();"
form example
and then you would have a javascript that has the ajax functionality...
you would also need to have the php file that would check this -> A == (B + C +D)
at the end of the php script you would put an echo yes or no or whatever you want
yes if they are equal, or no if they are not
then in the javascript code you would declare a var for the echo
and then check it
if var = yes then return true
else return false
on the form write onsumbit="return check_sum();"
form example
<form action="" method="post" onsubmit="return check_sum"> </form>
and then you would have a javascript that has the ajax functionality...
you would also need to have the php file that would check this -> A == (B + C +D)
at the end of the php script you would put an echo yes or no or whatever you want
yes if they are equal, or no if they are not
then in the javascript code you would declare a var for the echo
and then check it
if var = yes then return true
else return false
#7
Posted 11 April 2010 - 06:30 AM
another possibility is to parse the user input with strtotime(), but it's not error proof that either...
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall


Sign In
Create Account

Back to top









