SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to compute the aging time from datetime data's

    Hi..

    I have datetime data in my table kanban_data field chemicalweighing_dateEntry.
    sample data of chemicalweighing_dateEntry:

    2012-03-20 08:12:55
    2012-03-20 08:16:44
    2012-03-20 08:19:28
    2012-03-20 08:20:17
    2012-03-20 08:27:52
    2012-03-20 08:28:36
    2012-03-20 08:29:03
    2012-03-20 08:31:47
    2012-03-20 08:32:24
    2012-03-20 08:35:45

    I need to get the aging of chemicalweighing_dateEntry.

    using this formula:

    Aging time (00:00:00) = now() - SUM of chemicalweighing_dateEntry.


    I don't know what mysql function should I used to get the aging time.
    Thank you

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    try this --
    Code:
    SELECT SEC_TO_TIME(
             TIME_TO_SEC( CURRENT_TIMESTAMP ) -
             TIME_TO_SEC( SUM(chemicalweighing_dateEntry) )
                 ) AS aging_time
    that would make perfect sense if only it were possible to sum datetimes!!! (hint: it isn't)

    just what exactly does "sum of chemicalweighing_dateEntry" actually mean?
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    try this --
    Code:
    SELECT SEC_TO_TIME(
             TIME_TO_SEC( CURRENT_TIMESTAMP ) -
             TIME_TO_SEC( SUM(chemicalweighing_dateEntry) )
                 ) AS aging_time
    that would make perfect sense if only it were possible to sum datetimes!!! (hint: it isn't)

    just what exactly does "sum of chemicalweighing_dateEntry" actually mean?
    I tried it:

    Code:
    SELECT SEC_TO_TIME(
             TIME_TO_SEC( CURRENT_TIMESTAMP ) -
             TIME_TO_SEC( SUM(chemicalweighing_dateEntry) )
                 ) AS aging_time FROM kanban_data;
    the output display is: NULL

    Thank you

  4. #4
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I mean total of chemicalweighing_dateEntry.

    Thank you

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    I mean total of chemicalweighing_dateEntry.

    Thank you
    you can't add datetimes

    you're welcome
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried this:

    Code:
    SELECT sec_to_time((SUM(time_to_sec(chemicalweighing_dateEntry))) - TIME_TO_SEC (NOW())) FROM kanban_data;
    I'm not sure if my output : 95:24:15 is correct.

    Thank you

  7. #7
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    just what exactly does "sum of chemicalweighing_dateEntry" actually mean?

    HINT: YOU CAN'T ADD DATETIMES
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  8. #8
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes,

    I just want to know if my query is correct.

    Thank you

  9. #9
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    Yes,

    I just want to know if my query is correct.

    Thank you
    no

    it isn't

    you're welcome
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  10. #10
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's wrong in my query?

    Thank you

  11. #11
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    What's wrong in my query?

    Thank you
    the fact that you're trying to sum datetimes

    if this farce is to continue, i insist that you explain what it means to sum datetimes
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  12. #12
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    the fact that you're trying to sum datetimes

    if this farce is to continue, i insist that you explain what it means to sum datetimes
    I need to sum the times and minus in now().

    so what query should I need?

    Thanks

  13. #13
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    I need to sum the times ...
    i think you need to step away from the computer for a day or so...
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •