PDA

View Full Version : php / sql question about dates


fogofogo
06-02-2006, 12:00 PM
Hi folks,

I have a form that submits a date in this format : June 2006, and I am trying to use it to select records in a mysql database, that stores the date in this format: 2006-06-01.

So I must change June 2006 into 2006-06-01 and then feed it into the feed the date into the SQL statement - right?? This is the part I am stuck on.

some thing like this?

$formattedDate = date("F Y", strtotime($month));

my code so far (which is probably way off), looks like this...

<?php

// print out the month that has been choosen

$month = $_POST['date'];
echo $month;

//$formattedDate = date("F Y", strtotime($month));

...
database stuff
...

$query = mysql_query("SELECT DISTINCT ddate, DATE_FORMAT(ddate, '%Y %M') ID FROM pokercredit");

// print out the records

while ($row = mysql_fetch_array($query)){
echo "$row[ID] $row[dfrom] $row[damount]<br>"; // name class and mark will be printed with one line break at the end
}

?>


I'm obviously way off but any advice would be great, as I'm totally stuck on this.

Thanks all

J

fogofogo
06-02-2006, 02:25 PM
fixed it - if anyone would like to see the code:

<?php
// print out the month that has been choosen
$month = $_POST['date'];
echo $month;

include("db.php");

// select the ddate
//echo "SELECT * FROM pokercredit WHERE DATE_FORMAT(ddate, '%Y %M')='.$month;

$query = mysql_query("SELECT * FROM pokercredit WHERE DATE_FORMAT(ddate, '%Y %M')='".$month."'");

// print out the records
while ($row = mysql_fetch_array($query)){
echo "$row[ID] $row[dfrom] $row[damount]<br>"; // name class and mark will be printed with one line break at the end
}

?>

it might be messy, but it works!