Jump to content

I need some development help.

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
agrtek

agrtek

    Newbie

  • Members
  • Pip
  • 3 posts
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.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
How is the user entering this data?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
agrtek

agrtek

    Newbie

  • Members
  • Pip
  • 3 posts

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
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
If you're using a dropdown, you can have the displayed value be completely different from the transmitted value. There area lot of options.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
agrtek

agrtek

    Newbie

  • Members
  • Pip
  • 3 posts
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!

#6
chad

chad

    Learning Programmer

  • Members
  • PipPipPip
  • 68 posts
well you could use ajax for that
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
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
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