Jump to content

can i convert a yyyy-mm-dd to full date?


flemingmike

Recommended Posts

hello, i have the following code and it is ok.  what im trying to do is convert a 2010-09-20 post from a form and have it read out as Monday September 20, 2010.

 

is this possible?

 

$dateselected="$_POST[Y]-$_POST[M]-$_POST[D]";


echo "<table border='1'>";
echo "<tr><td width='100%' colspan='4' align='center'>$_POST[M]-$_POST[D]-$_POST[Y]</td></tr>";

Link to comment
Share on other sites

displays nothing.  here is my whole code.  maybe i didnt put it in the right spot.

 

<?php
include 'config.php';


$d = date("d");
$m = date("m");
$y = date("Y");

?>

<form method="post">
Month: <select size="1" name="M">
<option selected><?php echo "$m"; ?></option>
<option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><opti

on>09</option><option>10</option><option>11</option><option>12</option>
</select> 
Day: <select size="1" name="D">
<option selected><?php echo "$d"; ?></option>
<option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><opti

on>09</option><option>10</option><option>11</option>option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17<

/option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</opti

on><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option>
</select> 
Year: <select size="1" name="Y">
<option selected><?php echo "$y"; ?></option>
<option>2010</option><option>2011</option>
</select>   
<input name="add" type="submit" id="add" value="GO"> </form>

<?php



if(isset($_POST['add']))
{


$dateselected="$_POST[Y]-$_POST[M]-$_POST[D]";

date( 'l, F j, Y', strtotime($dateselected) );

echo "<table border='1'>";
echo "<tr><td width='100%' colspan='4' align='center'>$_POST[M]-$_POST[D]-$_POST[Y]</td></tr>";
echo "<tr>
<th>ID</th>
<th>Name</th>
<th>Job Number</th>
<th>Date</th>
</tr>";


$totalla=mysql_query("SELECT COUNT(*) FROM staff WHERE date = '$dateselected'");
$totalla=mysql_fetch_array($totalla);
$totalla="$totalla[0]";


if($totalla == 0){
echo "<tr><td width='100%' colspan='4'> There is currently no techs scheduled for today.</td></tr>";
}




$result = mysql_query("SELECT * FROM staff WHERE date = '$dateselected'");
while($row = mysql_fetch_array($result))
{



  echo "<tr>";
  echo "<td>" . $row["ID"] . "</td>";
  echo "<td>" . $row["Name"] . "</td>";
  echo "<td>" . $row["jobNO"] . "</td>";
  echo "<td>" . $row["Date"] . "</td>";
  echo "</tr>";
  }
echo "</table>";

}
else
{

echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Job Number</th>
<th>Date</th>
</tr>";
$result = mysql_query("SELECT * FROM staff WHERE date >= '".date('Y-m-d').' 00:00:00'."' AND date < '".date('Y-m-d').' 23:59:59'."' ");
while($row = mysql_fetch_array($result))
{


  echo "<tr>";
  echo "<td>" . $row["ID"] . "</td>";
  echo "<td>" . $row["Name"] . "</td>";
  echo "<td>" . $row["jobNO"] . "</td>";
  echo "<td>" . $row["Date"] . "</td>";
  echo "</tr>";
  }
echo "</table>";


}


?>

Link to comment
Share on other sites

What is the value of $dateselected when you run the script?

 

$dateselected="$_POST[Y]-$_POST[M]-$_POST[D]";

 

I ask because those $_POST values don't look right...

 

$dateselected="{$_POST['Y']}-{$_POST['M']}-{$_POST['D']}";

 

Sorry, I am unable to test this at the moment though

Link to comment
Share on other sites

i have 3 drop down boxes named "d, m and y"

 

when you select a day month and year it will show the results from the database that have that yyyy-mm-dd in the date column.

 

i want it to display with text the selected date.  right now it would show 05-22-2010 if i selected that in the drop down list.  im hoping i can convert that to Tuesday May 22, 2010.  this data isnt coming from a database at all, just from the post info.

Link to comment
Share on other sites

No they don't, they are all missing the value= attribute. They should each read <option value="some_value">Some Value</option>. At any rate, I went through and simplified the code a little for you and made some corrections. See my comment in the code where the formatted date string is as to why it wasn't doing anything. I quickly tested this, and it seems to work, so give it a go.

 

<?php
include 'config.php';
$d = date("d");
$m = date("m");
$y = date("Y");?>

<form method="post">
Month: <select size="1" name="M">
<option selected="selected" value="<?php echo $m; ?>"><?php echo $m; ?></option>
<?php
$mlist = range( 1,12 );
foreach ($mlist as $v ) {
   echo "<option value=\"$v\">$v</option>\n";
}
?>
</select>
Day: <select size="1" name="D">
<option selected="selected" value="<?php echo $d; ?>"><?php echo $d; ?></option>
<?php
$dlist = range( 1,31 );
foreach( $dlist as $v ) {
   echo "<option value=\"$v\">$v</option>\n";
}
?>
</select>
Year: <select size="1" name="Y">
<option selected="selected" value="<?php echo $y; ?>"><?php echo $y; ?></option>
<option value="2010">2010</option>
<option value="2011">2011</option>
</select>   
<input name="add" type="submit" id="add" value="GO"> </form>
<?php
if(isset($_POST['add'])) {
$dateselected=$_POST['Y'] . '-' . $_POST['M'] . '-' . $_POST['D'];

// nothing is being done with the result of it . . . needs to be echoed, or stored in a variable, etc.
$new_date = date( 'l, F j, Y', strtotime($dateselected) );


echo "<table border='1'>";
echo "<tr><td width='100%' colspan='4' align='center'>$new_date</td></tr>"; // changed this line to echo formatted date
echo "<tr>
<th>ID</th>
<th>Name</th>
<th>Job Number</th>
<th>Date</th>
</tr>";
$totalla=mysql_query("SELECT COUNT(*) FROM staff WHERE date = '$dateselected'");
$totalla=mysql_fetch_array($totalla);
$totalla="$totalla[0]";
if($totalla == 0){
echo "<tr><td width='100%' colspan='4'> There is currently no techs scheduled for today.</td></tr>";
}
$result = mysql_query("SELECT * FROM staff WHERE date = '$dateselected'");
while($row = mysql_fetch_array($result))
{echo "<tr>";
echo "<td>" . $row["ID"] . "</td>";
echo "<td>" . $row["Name"] . "</td>";
echo "<td>" . $row["jobNO"] . "</td>";
echo "<td>" . $row["Date"] . "</td>";
echo "</tr>";
}
echo "</table>";}
else
{echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Job Number</th>
<th>Date</th>
</tr>";
$result = mysql_query("SELECT * FROM staff WHERE date >= '".date('Y-m-d').' 00:00:00'."' AND date < '".date('Y-m-d').' 23:59:59'."' ");
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row["ID"] . "</td>";
echo "<td>" . $row["Name"] . "</td>";
echo "<td>" . $row["jobNO"] . "</td>";
echo "<td>" . $row["Date"] . "</td>";
echo "</tr>";
}
echo "</table>";
}
?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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