Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: SQL Time Calculation

  1. #1
    Junior Member r12ki's Avatar
    Join Date
    May 2009
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default SQL Time Calculation

    Is there someone help me to solve my probl ?? I was making a program, actually a parking system program. I have something confused me. How to calculate time in SQL DB ?? I've created enterTime and exitTime as DATETIME data type, and I want to know duration between enterTime and exitTime (how long does the vehicle park). Can you help this...

    Thanx for all your attentions


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: SQL Time Calculation

    Hello r12ki,

    Does your Java application write the enterTime & exitTime to the database?

    If so, I would work out the time parked in Java and then write the result to the database also.

    Or, you could use your application to extract the enterTime & exitTime from the database and then work it out that way.
    Ideally the first way would be best..

    Please update me and we can take it from there.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: SQL Time Calculation

    I've not worked a whole lot with datetime in SQL but I think I would just solve this by storing a long instead and use System.currentTimeMillis() to get the time and store that.

    then all you need to do is:

    final long duration = exitTime - enterTime;
    Then you can use that long value to pass into whatever date library you want to use, I'd recommend Joda Time - Java date and time API - Home

    Good luck!

    // Json

  4. #4
    Junior Member r12ki's Avatar
    Join Date
    May 2009
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: SQL Time Calculation

    @JavaPF : Yes, it does. From the Apps it'll write enterTime from the begining, then write exitTime at last. enterTime is in "datalog" table, and exitTime in "outlog" table. In the "outlog" there is a field named "durasi" (mean=duration). How to get "durasi" automatically ??

    @Json : Thanks for suggestion, you helped..

Similar Threads

  1. Changing colors of large image in real time
    By chals in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: May 7th, 2009, 05:06 AM
  2. How to Get the current date and time
    By JavaPF in forum Java Programming Tutorials
    Replies: 2
    Last Post: December 2nd, 2008, 01:55 PM

Tags for this Thread