473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Doing time calculations...

Howdy,

For a project I am working on right now I need to be able to calculate the
time difference between to given times.
(For example...The difference between 11:30 am and 1:45pm being 2:15)

Right now the input is setup as 2 text boxes, 2 dropdowns, and 2 radio
groups. The text boxes get the hour entered into them, the drop downs holdd
a list contaning 00, 15, 30, and 45 (the minutes) and the radio groups being
am or pm.

Is it possible to use that configuration and somehow get the time
difference? or do I need to change the input? The goal is to be able to
enter the two values and immediately see a calculated difference in a third
textbox on the page.

I'm thinking something like....
User enters hour in first text box(textHFrom) - 11
User selects minue value from second dropdown(cboMFrom) - 30
User selects am/pm from radio group(radioF) - am
User enters hour in second text box(textHTo) - 1
User selects minue value from second dropdown(cboMTo) - 45
User selects am/pm from radio group(radioT) - pm

onChange of second RadioGroup time is calculated and result in inserted into
third text box(textHours) - 2:15

I'm not sure if/how to bet do this.

Thanks,
Jason
Jul 16 '05 #1
2 9769
"Jason Reljac" <jm****@hotmail.com> wrote in message
news:<vh************@corp.supernews.com>...

For a project I am working on right now I need to be able to calculate the
time difference between to given times.
(For example...The difference between 11:30 am and 1:45pm being 2:15)


Read up on strtotime() function:

http://php.net/strtotime

You'll be surprised how much it lets you get away with. Using this
function, you can actually compute the difference between 'last
Friday 5:37 PM' and '+2 hours 14 minutes' (meaning, 2 hours 14 minutes
from now), with both arguments specified as shown.

So let's say you have a form that has two text inputs, 'start' and
'end'. To compute the time difference, you would do something like
this:

$start = strtotime ($_GET['start']);
if ($start == -1) {
die ('Invalid start time');
}
$end = strtotime ($_GET['end']);
if ($end == -1) {
die ('Invalid end time');
}
$diff = $end - $start;

Now $diff contains the difference between two times stated in seconds.
Converting it into minutes and hours should be rather trivial...

Cheers,
NC
Jul 16 '05 #2
Many, many thanks...with a small change, that worked just right.

Jason
"Nikolai Chuvakhin" <nc@iname.com> wrote in message
news:32**************************@posting.google.c om...
"Jason Reljac" <jm****@hotmail.com> wrote in message
news:<vh************@corp.supernews.com>...

For a project I am working on right now I need to be able to calculate the time difference between to given times.
(For example...The difference between 11:30 am and 1:45pm being 2:15)


Read up on strtotime() function:

http://php.net/strtotime

You'll be surprised how much it lets you get away with. Using this
function, you can actually compute the difference between 'last
Friday 5:37 PM' and '+2 hours 14 minutes' (meaning, 2 hours 14 minutes
from now), with both arguments specified as shown.

So let's say you have a form that has two text inputs, 'start' and
'end'. To compute the time difference, you would do something like
this:

$start = strtotime ($_GET['start']);
if ($start == -1) {
die ('Invalid start time');
}
$end = strtotime ($_GET['end']);
if ($end == -1) {
die ('Invalid end time');
}
$diff = $end - $start;

Now $diff contains the difference between two times stated in seconds.
Converting it into minutes and hours should be rather trivial...

Cheers,
NC

Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Sims | last post by:
Hi, I have a field in my DB that saves the date/time as a integer. I get the time on my server using the time() function. now, moving away from php and looking at (My)SQL only. If I use...
2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
11
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m...
1
by: bluerocket | last post by:
I have searched this group, and am not finding the answer I am looking for -- hope you can help. I have a front-end MS Access database hooked via a MyODBC link to a MySQL database. A modified...
4
by: Morten Wennevik | last post by:
Hi, Upon clicking a button I perform some heavy server side calculations lasting up to five minutes. During this time, the web page appear to be loading the response page. Is there some...
5
by: cvisal | last post by:
Hi all Im working on productivity calculations (Time calculations) and need some help in coding. Database Tool:MS-Access 2003. The general operator punch-in time is 5:30 AM and the punch-out...
2
by: chudson007 | last post by:
This is a very general quastion..... I regularily take data extracts from a SQL server database drop them in excel and run a macro on the data. The macro does nothing more complicated than...
18
by: Dirk Hagemann | last post by:
Hello, From a zone-file of a Microsoft Active Directory integrated DNS server I get the date/time of the dynamic update entries in a format, which is as far as I know the hours since january 1st...
3
by: Steve | last post by:
I am trying to calculate elapsed travel times for flights. My plan is to enter the local departure time, the departure city and the local arrival time and city. These times would be standardised...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.