pietbez Posted February 15, 2008 Share Posted February 15, 2008 need help please! i want to show only current and future events. in other words, filter out all events older than "today" but there is a catch, at the moment, my date field on the db is in this format "12.02.2008" instead of "2008.02.12" can anyone help please? <? include('../qazwsxedc/config.php'); mysql_connect($server,$username,$password); @mysql_select_db($database) or die ("Unable to connect to the database"); $do=mysql_query ("SELECT event_date FROM calendar_events WHERE event_date>'????????' "); $x=mysql_num_rows($do); if ($x>0) { while ($row = mysql_fetch_array($do, MYSQL_ASSOC)) { $event_date=$row["event_date"];} } echo "date=".$event_date; ?> Link to comment https://forums.phpfreaks.com/topic/91322-date-format/ Share on other sites More sharing options...
craygo Posted February 15, 2008 Share Posted February 15, 2008 use strtotime. You are better off having the actual date in the table, that way you could use mysql to format it, but since you don't $today = date("U"); while ($row = mysql_fetch_array($do, MYSQL_ASSOC)) { $event_date=date("U", strtotime($row["event_date"])); if($event_date > $today){ echo $row["event_date"]; } } Ray Link to comment https://forums.phpfreaks.com/topic/91322-date-format/#findComment-468010 Share on other sites More sharing options...
richardw Posted February 15, 2008 Share Posted February 15, 2008 Just to have, a method to pull apart your date. The previos post is right as this will not sort correctly in the MySQL code <?php $takeapart = "12.02.2008"; $start_here = explode('.',$takeapart); $month = $start_here[0]; $day = $start_here[1]; $year = $start_here[2]; echo $year.".".$day.".".$month; $post_date = date('m.d.Y'); echo $post_date; // in the database format ?> Link to comment https://forums.phpfreaks.com/topic/91322-date-format/#findComment-468021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.