Laugh at . . . *ahem* . . . with me. (military time)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
HungryMind
Forum Commoner
Posts: 41
Joined: Fri Jun 20, 2003 10:33 am
Location: Alameda, CA

Laugh at . . . *ahem* . . . with me. (military time)

Post by HungryMind »

Well, I recently got into the whole getlastmod() function and, from the examples that I was looking at (thanks a lot php.net!), I used "H" to display the hour.

Weeeeeeelllllll, this just wasn't sufficient for my needs because I hate reading military time. I think its annoying and other things, but thats for another article. Anyway, I decided to go about writing a little script that converts the military time to standard am, pm stuff.

Being a beginner, or relative beginner, this task took me quite some time (about 45 minutes) and gave me a pretty decent headache. I ended up taking two ibuprofen and finishing a pretty awesome, useful (har har) script! You wanna see it?

Code: Select all

/*	Copyright © 2003 Brandon Paredes. All rights reserved.
	brandon@paredes.cc	*/
$hour_convert = date ("H", getlastmod());
$hour = 0;
if ($hour_convert > 12) {
	$hour = $hour_convert - 12;
} else {
	$hour = $hour_convert;
}

$am_pm = " ";
if ($hour_convert < 13) {
	$am_pm .= "am";
} else {
	$am_pm .= "pm";
}

echo "<b>Date Uploaded:</b> " . date ("F d Y $hour:i", getlastmod());
echo "$am_pm.";
echo "<br>";
Now, we all know that I could have just done away with all of that work and just put "h" in place of "H" and done the EXACT SAME thing! Okay, so now you can laugh at me. However, before you do, please take into consideration that I am a newbie AND, most importantly, I did write code to fix my problem instead of posting a dumb question on this forum! Laugh it up, guys and don't steal my VERY USEFUL :roll: script . . .

Yuk, Yuk,
Brandon
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post by brewmiser »

I am not for sure what to say......but......

GOOD JOB !!

LOL !! :lol:

( sometimes we just have to laugh, if not, we might go "postal" ! )
Post Reply