working with times

Associate
Joined
18 Oct 2002
Posts
710
Location
Somerset
I am trying to put a page together that works with times,

The user will input a 'start' time,

make several choices from selection menus which will result in a 'to do' time in secs,

this 'to do' time needs to be added to the 'start' time to give a 'finish' time.

I have done something like this in C++ before but do not have the code to look at and try to alter and i am currently drawing a blank on the best way to do this on a web page.

Any one have any ideas or pointers or know the best place to look for help?

Thanks
 
More info needed really before we can help.

What server side technology are you already using (If you've started already?)? Does the calculation need to be server side or can it be done client side? Once you've answered these questions it should be a fairly simple answer, pretty much every web language has decent datetime manipulation.


Mick.
 
Thanks Mickey

Server is running from home,
Wampserver2 running so apache, php, mysql all on the go,

The calculation can be done server side or client side, i dont see any reason to ake it one or the other at this point.

The page in question is going to end up being in what ever gives we time manipulation i can work with :)
Although a rough outline has been put together in html, just to make sure i have included everything needed on the page, nothing actually 'working' behind it yet.
 
Client side:

Code:
<script language="javascript">
    
    function fnDoit(){
      var SecondsToAdd = 20;
      var dtNow = new Date();
      var hour = dtNow.getHours();
      var min = dtNow.getMinutes();
      var sec = dtNow.getSeconds();
      alert("StartTime:" + hour + ":" + min + ":" + sec);
    
      var NewDate = fnAddSeconds(dtNow,SecondsToAdd);
    
      var nhour = NewDate.getHours();
      var nmin = NewDate.getMinutes();
      var nsec = NewDate.getSeconds();
      alert("EndTime:" +nhour + ":" + nmin + ":" + nsec);
    }
    
    function fnAddSeconds(d, Seconds){
        var curr_sec = d.getSeconds();
        curr_sec = parseInt(curr_sec) + parseInt(Seconds);
        d.setSeconds(curr_sec);       
       return d;
    }

    
    
    </script>

Change the dtNow to whatever date object you have for the start time and the SecondsToAdd to whatever needs to be added.


Simon
 
Last edited:
You could probably get it down to 1 line if you care about bandwidth!

dtNow.setSeconds(parseInt(dtNow.getSeconds()) + parseInt(Seconds));

(note I didn't check this!)

Simon
 
Back
Top Bottom