<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Convert 24 hour (military) time to 12 hour (am/pm) time in php</title>
	<atom:link href="http://style-vs-substance.com/programming/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://style-vs-substance.com/programming/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 23 Jun 2010 17:37:21 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: siraj khan</title>
		<link>http://style-vs-substance.com/programming/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/comment-page-1/#comment-3366</link>
		<dc:creator>siraj khan</dc:creator>
		<pubDate>Thu, 10 Jun 2010 08:47:37 +0000</pubDate>
		<guid isPermaLink="false">http://style-vs-substance.com/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/2007/10/#comment-3366</guid>
		<description>thank u so much!!</description>
		<content:encoded><![CDATA[<p>thank u so much!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rob barclay</title>
		<link>http://style-vs-substance.com/programming/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/comment-page-1/#comment-2933</link>
		<dc:creator>rob barclay</dc:creator>
		<pubDate>Thu, 15 Apr 2010 03:07:49 +0000</pubDate>
		<guid isPermaLink="false">http://style-vs-substance.com/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/2007/10/#comment-2933</guid>
		<description>Thanks for the interpretation of strtotime.  I couldn&#039;t make heads or tails of the description on php.net.  You are the BEST</description>
		<content:encoded><![CDATA[<p>Thanks for the interpretation of strtotime.  I couldn&#8217;t make heads or tails of the description on php.net.  You are the BEST</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Mayes</title>
		<link>http://style-vs-substance.com/programming/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/comment-page-1/#comment-2883</link>
		<dc:creator>Jim Mayes</dc:creator>
		<pubDate>Tue, 06 Apr 2010 19:17:45 +0000</pubDate>
		<guid isPermaLink="false">http://style-vs-substance.com/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/2007/10/#comment-2883</guid>
		<description>yup, you can just as easily assign it to a variable as echo it out.</description>
		<content:encoded><![CDATA[<p>yup, you can just as easily assign it to a variable as echo it out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://style-vs-substance.com/programming/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/comment-page-1/#comment-2882</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 06 Apr 2010 19:09:07 +0000</pubDate>
		<guid isPermaLink="false">http://style-vs-substance.com/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/2007/10/#comment-2882</guid>
		<description>Thanks for that explanation, I did figure out how to do it with if else, but this is much easier. I&#039;m putting the value into my database, so instead of echoing it directly, would I just define the variable to something like this?

$event_start = date(&#039;Y-m-d H:i:s&#039;, strtotime($event_start));</description>
		<content:encoded><![CDATA[<p>Thanks for that explanation, I did figure out how to do it with if else, but this is much easier. I&#8217;m putting the value into my database, so instead of echoing it directly, would I just define the variable to something like this?</p>
<p>$event_start = date(&#8217;Y-m-d H:i:s&#8217;, strtotime($event_start));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Mayes</title>
		<link>http://style-vs-substance.com/programming/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/comment-page-1/#comment-2881</link>
		<dc:creator>Jim Mayes</dc:creator>
		<pubDate>Tue, 06 Apr 2010 17:01:37 +0000</pubDate>
		<guid isPermaLink="false">http://style-vs-substance.com/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/2007/10/#comment-2881</guid>
		<description>Ok, let me see if I understand what you are describing Jeff. You have a form with fields for date and time and you have a select box giving the options of &quot;AM&quot; or &quot;PM&quot;. If that&#039;s correct, you can avoid doing any hour math by just using strtotime().

Change the am/pm select box to have literal values. So the selection for &quot;AM&quot; would provide the value &quot;AM&quot;. Selection for &quot;PM&quot; would give the value &quot;PM&quot;.

Now, when the form is submitted concatenate the parts together into a string that is in US English date format

&lt;pre class=&quot;brush:php&quot;&gt;
$event_start = $start_month . &#039;/&#039; . $start_day . &#039;/&#039;. $start_year . &#039; &#039; . $event_start_time_hh . &#039;:&#039; . $event_start_time_mm . &#039; &#039; . $event_start_time_ampm;
&lt;/pre&gt;

Then pass that string thru strtotime() and into date() to format however you need it.

&lt;pre class=&quot;brush:php&quot;&gt;
echo date(&#039;Y-m-d H:i:s&#039;, strtotime($event_start));
&lt;/pre&gt;

Here&#039;s a full example

&lt;pre class=&quot;brush:php&quot;&gt;
// assume these values are set by your form being submitted
$start_month = &#039;04&#039;;
$start_day = &#039;06&#039;;
$start_year = &#039;2010&#039;;
$event_start_time_hh = &#039;2&#039;;
$event_start_time_mm = &#039;30&#039;;
$event_start_time_ampm = &#039;pm&#039;;

// concatenate the parts into US English formatted date
$event_start = $start_month . &#039;/&#039; . $start_day . &#039;/&#039;. $start_year . &#039; &#039; . $event_start_time_hh . &#039;:&#039; . $event_start_time_mm . &#039; &#039; . $event_start_time_ampm;

// output full MySQL 24 hour format
echo date(&#039;Y-m-d H:i:s&#039;, strtotime($event_start));

//prints &quot;2010-04-06 14:30:00&quot;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Ok, let me see if I understand what you are describing Jeff. You have a form with fields for date and time and you have a select box giving the options of &#8220;AM&#8221; or &#8220;PM&#8221;. If that&#8217;s correct, you can avoid doing any hour math by just using strtotime().</p>
<p>Change the am/pm select box to have literal values. So the selection for &#8220;AM&#8221; would provide the value &#8220;AM&#8221;. Selection for &#8220;PM&#8221; would give the value &#8220;PM&#8221;.</p>
<p>Now, when the form is submitted concatenate the parts together into a string that is in US English date format</p>
<pre class="brush:php">
$event_start = $start_month . '/' . $start_day . '/'. $start_year . ' ' . $event_start_time_hh . ':' . $event_start_time_mm . ' ' . $event_start_time_ampm;
</pre>
<p>Then pass that string thru strtotime() and into date() to format however you need it.</p>
<pre class="brush:php">
echo date('Y-m-d H:i:s', strtotime($event_start));
</pre>
<p>Here&#8217;s a full example</p>
<pre class="brush:php">
// assume these values are set by your form being submitted
$start_month = '04';
$start_day = '06';
$start_year = '2010';
$event_start_time_hh = '2';
$event_start_time_mm = '30';
$event_start_time_ampm = 'pm';

// concatenate the parts into US English formatted date
$event_start = $start_month . '/' . $start_day . '/'. $start_year . ' ' . $event_start_time_hh . ':' . $event_start_time_mm . ' ' . $event_start_time_ampm;

// output full MySQL 24 hour format
echo date('Y-m-d H:i:s', strtotime($event_start));

//prints "2010-04-06 14:30:00"
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://style-vs-substance.com/programming/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/comment-page-1/#comment-2880</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Tue, 06 Apr 2010 16:32:29 +0000</pubDate>
		<guid isPermaLink="false">http://style-vs-substance.com/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/2007/10/#comment-2880</guid>
		<description>Very nice, thank you.</description>
		<content:encoded><![CDATA[<p>Very nice, thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://style-vs-substance.com/programming/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/comment-page-1/#comment-2875</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 06 Apr 2010 03:49:57 +0000</pubDate>
		<guid isPermaLink="false">http://style-vs-substance.com/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/2007/10/#comment-2875</guid>
		<description>How would this be done for a form input using variables for the time?

For instance, if I have variables that I string together to show the date &amp; time as:

$event_start = $start_year.&quot;-&quot;.$start_month.&quot;-&quot;.$start_day.&quot; &quot;.$event_start_time_hh.&quot;:&quot;.$event_start_time_mm.&quot;:00&quot;;

On my form I also have a field for my variable: $event_start_time_ampm with value for AM being &#039;00&#039; and PM is &#039;12&#039;.

I was trying to make an if else statement:

	if ($_POST[&#039;event_start_time_ampm&#039;] == &#039;12&#039;) {      
		$_POST[&#039;event_start_time_hh&#039;] = $_POST[&#039;event_start_time_hh&#039;] + 12;
	} else {
	$_POST[&#039;event_start_time_hh&#039;];	
	}


But, it&#039;s not working, it only formats the time as AM.</description>
		<content:encoded><![CDATA[<p>How would this be done for a form input using variables for the time?</p>
<p>For instance, if I have variables that I string together to show the date &amp; time as:</p>
<p>$event_start = $start_year.&#8221;-&#8221;.$start_month.&#8221;-&#8221;.$start_day.&#8221; &#8220;.$event_start_time_hh.&#8221;:&#8221;.$event_start_time_mm.&#8221;:00&#8243;;</p>
<p>On my form I also have a field for my variable: $event_start_time_ampm with value for AM being &#8216;00&#8242; and PM is &#8216;12&#8242;.</p>
<p>I was trying to make an if else statement:</p>
<p>	if ($_POST['event_start_time_ampm'] == &#8216;12&#8242;) {<br />
		$_POST['event_start_time_hh'] = $_POST['event_start_time_hh'] + 12;<br />
	} else {<br />
	$_POST['event_start_time_hh'];<br />
	}</p>
<p>But, it&#8217;s not working, it only formats the time as AM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://style-vs-substance.com/programming/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/comment-page-1/#comment-2417</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Mon, 18 Jan 2010 00:50:01 +0000</pubDate>
		<guid isPermaLink="false">http://style-vs-substance.com/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/2007/10/#comment-2417</guid>
		<description>Thanks a lot, it was very very helpful to get it all assembled &amp; ready to go, now I can finish designing my CMS !</description>
		<content:encoded><![CDATA[<p>Thanks a lot, it was very very helpful to get it all assembled &amp; ready to go, now I can finish designing my CMS !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://style-vs-substance.com/programming/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/comment-page-1/#comment-2354</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Thu, 07 Jan 2010 18:38:19 +0000</pubDate>
		<guid isPermaLink="false">http://style-vs-substance.com/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/2007/10/#comment-2354</guid>
		<description>You made my evening!!! Thanks so much!</description>
		<content:encoded><![CDATA[<p>You made my evening!!! Thanks so much!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sujatha</title>
		<link>http://style-vs-substance.com/programming/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/comment-page-1/#comment-2281</link>
		<dc:creator>Sujatha</dc:creator>
		<pubDate>Sun, 27 Dec 2009 15:48:46 +0000</pubDate>
		<guid isPermaLink="false">http://style-vs-substance.com/convert-24-hour-military-time-to-12-hour-ampm-time-in-php/2007/10/#comment-2281</guid>
		<description>You are my saviors!</description>
		<content:encoded><![CDATA[<p>You are my saviors!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
