Jump to content

date format


pietbez

Recommended Posts

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
Share on other sites

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
Share on other sites

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
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.