Explode function not working properly

Discussion in 'PHP' started by j_o, Aug 1, 2011.

  1. #1
    Hi everyone,

    I have written the following function that converts from 12-hour time to 24-hour time. It is not the best way to do it but since I had to add the 24-hour time to a system that was previously built with 12-hour time I came up with this:

    
    function get_m_time($AppntmntTime){
    	$Ntime = explode(":",$AppntmntTime);
    	if($Ntime[1] = "00am"){
    		$mtime = $Ntime[0];
    	} else {
    		$mtime = $Ntime[0]+12;
    	}
    	die($AppntmntTime."<br/>".$Ntime[1]."<br/>".$mtime);
    	return $mtime;
    }
    
    PHP:
    Note that the die function is just in there temporarily while I am trying to debug it. When I pass in a time that has 'pm' in it for example 1:00pm I get the following output from the die function.
    1:00pm (AppntmntTime)
    00am (Ntime[1])
    1 (mtime)

    However the 2nd line there should be 00ppm and the last line should be 13. Any idea why the explode function is doing that?

    Thanks for any help in advance, I really appreciate it.
     
    j_o, Aug 1, 2011 IP
  2. Nebula525

    Nebula525 Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not to sure either I'm just a novice but it looks fine to me...
     
    Nebula525, Aug 1, 2011 IP
  3. j_o

    j_o Well-Known Member

    Messages:
    516
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    113
    #3
    I just figured it out, the if statment had = instead of == so it was assigning the $Ntime[1] element to be "00am".
     
    j_o, Aug 1, 2011 IP