SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast Cabbage's Avatar
    Join Date
    Jun 2001
    Location
    New Jersey
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    adding number in a char field

    We have this program at my job that uses a language similar to JavaScript. Someone has set up a form that tracks the time people work on different projects. This person decided to make this field a character field. Now they want to add up all the time that was worked on for this project. Since they are char fields I told them it wasn't possible.

    Is there a way to convert the char's into numbers and add the time?
    They are setup in multiples of 15 like this
    0:30
    0:15
    3:45
    1:00 (60 minutes or 1 hour)
    2:15
    ~Cabbage
    http://www.jimmieschickenshack.net
    want to trade live recordings? JCS, Smashing Pumpkins, Local H, Toadies

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: adding number in a char field

    Originally posted by Cabbage
    We have this program at my job that uses a language similar to JavaScript.
    Does the language have a name?

    Anyway, there must be functions that can take each string, find the ":", add L*60 + R to a variable S and then print S

    (L=left part converted to integer, R=right part, S=sum)

  3. #3
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In javascript:

    var v = "1:45";
    var i = v.indexOf(":");
    var l = parseInt(v.substring(0, i));
    var r = parseInt(v.substring(i+1));
    var s = l*60+r;
    alert(s);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •