Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    119
    Thanks
    6
    Thanked 0 Times in 0 Posts

    how to get mysql query max time

    hi i need to get max time and min time

    i have query

    $sqlstr41 ="SELECT Max(time_format(Barcode_Time, '%k:%i:%s')) as maxtime FROM Barcode_FP WHERE date_barcode='$today1' AND Productionh='10' ";
    echo $sqlstr41;
    $result41 = mysql_query($sqlstr41);
    $record41 = mysql_fetch_array( $result41 );

    but this will not getting the correct maxtime


    plz help me to get the max time6

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    perhaps you should first get the max time and then format it the way you want:
    SELECT time_format(max(Barcode_Time), '%k:%i:%s')
    I am the luckiest man in the world

  • #3
    Regular Coder
    Join Date
    Sep 2010
    Posts
    119
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Roelf View Post
    perhaps you should first get the max time and then format it the way you want:
    SELECT time_format(max(Barcode_Time), '%k:%i:%s')
    hi

    but i have use your query but i got only the

    max time as 9:59:02 but my max time is 10:29:15

    why is that plz help me to solve this

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    and what is your output when you omit the formatting?
    I am the luckiest man in the world

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    Or are you trying to find the max value of the time part of a datetime field, regardless of the datepart?
    I am the luckiest man in the world

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Just do
    Code:
    $sql = "SELECT MAX(TIME(Barcode_Time)) as maxtime 
            FROM Barcode_FP 
            WHERE date_barcode='$today1' AND Productionh='10' ";
    and then format maxtime in your PHP code instead of in MySQL.

    But if you *MUST* do it in MySQL, then:
    Code:
    $sql = "SELECT FORMAT_TIME( MAX(TIME(Barcode_Time)), '%k:%i:%s') as maxtime 
            FROM Barcode_FP 
            WHERE date_barcode='$today1' AND Productionh='10' ";
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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