Jump to content

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


marknt

Recommended Posts

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:

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

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

Please help thanks a lot!
Cheers
Link to comment
Share on other sites

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

I think im just lucky  ;D

Here is my code:
[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>";

[/code]

Thank you for replying Sir Alpine.
Cheers
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.