facebook

Calculating the Difference Between Two Dates

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #334681 Reply

    Hello:

    I am trying (real hard) to write the code for my zipped example below. I would want the user to enter the beginning date and the ending date (and times) into the first two fields and then it would calculate the difference and put it in the bottom field.

    I do not have it configured that way because I am trying to get a simple example to work. I saw this coding in some examples.

    Please don’t laugh. I am trying to learn. Please help.

    I appreciate all of your help.

    Celeste

    Attachments:
    You must be logged in to view attached files.
    #334698 Reply

    Max87
    Member

    Hi CelesteP,
    IMO you should convert your input dates into timestamps, then timestamp1-timestamp2 and then convert it back to human format.
    I found this, it may be good example:
    http://stackoverflow.com/questions/11509814/date-string-conversion-to-unix-timestamp-in-javascript-jquery

    I try to look at your code today.

    #334700 Reply

    paulD
    Member

    Hi Celeste

    Did you get the date picker working? I managed to get the picker to work for both date and time. i’ll upload a demo if you want to go down that route.

    I’m trying to do the same with time so I’m in the same boat.

    Max if you could put together a quick example I would be your best friend forever.

    So the way i understand it you have to convert the date object to a unix format, do the calculation then convert it back to a date object.

    Its really hard this programming lark!

    #334707 Reply

    Max87
    Member

    Hi paulD,
    I can create example for you, pls let me know what that app should do exactly.

    #334710 Reply

    paulD
    Member

    Hi Max your a legend for doing this! I’ve attached a file with what i want to do. Its pretty simple really, I want to just calculate the difference between two times and display the result in a text field.

    The file has two time pickers and a results text field. Ive done a fair bit of searching and I Kind of think i kind of know what to do, I’ve got the timepickers working but I just don’t know how to implement the calculation it in javascript? I need to extract the value of the timepickers, convert to unix then calculate the values, covert back to hh:mm:ss and finally display the result in the text field.

    does that sound right?

    Sorry for stomping all over your thread Celeste hope you don’t mind but I think we are after the same thing?

    Attachments:
    You must be logged in to view attached files.
    #334711 Reply

    Max87
    Member

    Hi paulD,
    I have quick example. It has some bugs 🙂 so please debug it to meet your needs.
    I hope this helps

    Attachments:
    You must be logged in to view attached files.
    #334717 Reply

    paulD
    Member

    thanks mate i will have a look through it and see how we go. thanks for taking the time to help out.

    paul

    #334718 Reply

    Max87
    Member

    Yeah, no problem, you’re welcome

    #334733 Reply

    Maxx:

    Thank you for helping Paul and I. I will be your best friend forever also.

    Paul:
    Stomp Away! Yes, I believe we are after the same thing and I will look at your example and Maxx’s and try to make mine work. It’s very frustrating because I know what to do, I just am not sure of the coding.

    Thank you all so much for the help. It is really appreciated.

    Celeste

    #334734 Reply

    Max87
    Member

    I can recommend you Mobiscroll if you want to use datetime pickers, it’s easy to learn and use.
    Also, this date conversion thing is harder than I thought, but I’m sure you can edit my code to meet your requirements(f.e timezone). Basically, it’s only math – you convert your time to milliseconds and converting back to normal format is about dividing that number by right number…One thing I forgot – my script requires to format your inputs into mm/dd/yyyy hh:mm (standard formatting)

    edit: I found javascript library which could dothe hard part for you…I look at it and let you know.

    #334752 Reply

    paulD
    Member

    @CelesteP wrote:

    Maxx:

    Thank you for helping Paul and I. I will be your best friend forever also.

    Paul:
    Stomp Away! Yes, I believe we are after the same thing and I will look at your example and Maxx’s and try to make mine work. It’s very frustrating because I know what to do, I just am not sure of the coding.

    Thank you all so much for the help. It is really appreciated.

    Celeste

    I so know exactly how you mean. I’ve done Actionscript 3 in the past but only really for animation and easy stuff! Javascript syntax is very similar but I am no natural programmer!! And the other problem is you google stuff and you get so many different answers to the same problem you don’t know where to start! In the last few months using mobione I’ve learned so much, but still feel like I’m staring up at Mount Everest!

    #334901 Reply

    paulD
    Member

    Hi Guys

    I got a working version after a lot of tears,tantrums and enough caffeine to kill an elephant. Levi from mobiscroll helped me out and pointed me in the right direction, top bloke!

    Anyway here is a test file with 2 timepickers which automatically updates a text field with the difference in time.

    Thanks

    Paul

    Attachments:
    You must be logged in to view attached files.
    #335486 Reply

    Hi Paul:

    I can’t get it to work. What is the format to input the time? 5:00:00 PM ??????

    Celeste

    #335487 Reply

    Paul:

    When I “view source” of the custom file there is no coding there.

    Celeste

    #335495 Reply

    paulD
    Member

    Sorry Celeste

    I think i know what when wrong with the demo. I have my project set up to bring in the mobiscroll javascript file from a remote folder on my hard drive.

    On the demo mobi page set the path to your mobiscroll JS file to your directory and it should work.

    If you have anymore probs let me know and i will upload another file.

    Paul

Viewing 15 posts - 1 through 15 (of 18 total)
Reply To: Calculating the Difference Between Two Dates

You must be logged in to post in the forum log in