convert 24 hour to 12 hour

Hello, in the code below, how would I convert 24 hour time to 12 hour time and put date format as 8/27/13?
Also how in the select statement could I add where wp_events_start_end.end_time is greater than 6pm?

Result: 2013-08-27 End Time: 19:30

[php]<?php
$username = “”;
$password = “”;
$hostname = “localhost”;

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die(“Unable to connect to MySQL”);
echo “
”;
?>

<?php //select a database to work with $selected = mysql_select_db("stormwi1_wrd1",$dbhandle) or die("Could not select stormwi1_wrd1"); ?> <?php //execute the SQL query and return records $result = mysql_query("SELECT wp_events_detail.id, wp_events_detail.event_name, wp_events_detail.start_date, wp_events_start_end.end_time FROM wp_events_detail join wp_events_start_end on wp_events_detail.id = wp_events_start_end.event_id WHERE wp_events_detail.start_date = curdate() - INTERVAL DAYOFWEEK(curdate())-3 DAY order by wp_events_detail.start_date"); //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo "".$row{''}." ".$row{'start_date'}. " End Time: ".$row{'end_time'}."
"; } ?> <?php //close the connection mysql_close($dbhandle); ?>[/php]

I’m going to turn this PHP question into a mysql question. You can do everything you want in the MySQL query…

[php]$result = mysql_query(“SELECT wp_events_detail.id,
wp_events_detail.event_name,
DATE_FORMAT(wp_events_detail.start_date,’%d-%m-%y’) start_date,
TIME_FORMAT(wp_events_start_end.end_time,’%h.%i.%s %p’) end_time,
FROM wp_events_detail
join wp_events_start_end on wp_events_detail.id = wp_events_start_end.event_id
WHERE wp_events_detail.start_date = curdate() - INTERVAL DAYOFWEEK(curdate())-3 DAY
and TIME_FORMAT(wp_events_start_end.end_time,’%H’) >= 18
order by wp_events_detail.start_date”);[/php]

I’m pulling data from an event expresso database, which is a Wordpress calendar plugin, for some reason they have end_time as a VARCHAR.

You can use the MySQL Function STR_TO_DATE function to convert it from VARCHAR…

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date

or you can just use date(‘m/d/Y’, $datevariable); easier to do it in the query though, if you can.

Sponsor our Newsletter | Privacy Policy | Terms of Service