Jump to content


Photo

Hep please....changing "10 PM" to military time


  • Please log in to reply
2 replies to this topic

#1 marknt

marknt
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts
  • LocationPhilippines

Posted 21 October 2006 - 05:17 AM

Hello people i need some help. Im figuring this out.

I have a variable $var="11 PM". I want to convert it into military time like this one ---> 23

here is my code but its not working:

$var = "10"; // this is equivalent to 10 PM

$military_time = date('H', $var);
echo "Hour: $var<br>";
echo "Military time: $military_time<br>";

Please help thanks a lot!
Cheers

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 21 October 2006 - 05:41 AM

$var = "10"; // this is equivalent to 10 PM

If your $var IS 10 it's not equivalent to 10 PM.... how does your full time format look like?
Just the number "10" is nothing to work width in formatting time.

#3 marknt

marknt
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts
  • LocationPhilippines

Posted 21 October 2006 - 05:53 AM

Hello sir alpine. I think i solved my own problem *sigh*  :D

I think im just lucky  ;D

Here is my code:

// this is a string
$mytime = "11:30 PM";
// Converting string time ( 11:30 PM ) to Military time (23:30)
$temp = strtotime("$mytime");
$military_time = date('H:i', $temp);

echo "String Time: $mytime<br>";
echo "Temp: $temp<br>";
echo "Military time: $military_time<br>";


Thank you for replying Sir Alpine.
Cheers




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users