angelsRock Posted October 13, 2007 Share Posted October 13, 2007 while($row2=mysql_fetch_array($exec2,MYSQL_BOTH)) { echo'<tr>'; echo"<td width=100 align=center>substr($row2[datePosted],0,10) </td>"; } why the display result for the date is substr(2007-10-13 23:51:48,0,10) instead of 2007-10-13 ?? Quote Link to comment https://forums.phpfreaks.com/topic/73094-date-display/ Share on other sites More sharing options...
Rithiur Posted October 13, 2007 Share Posted October 13, 2007 Function are not parsed inside strings, of course. You should be using something like this instead: while($row2=mysql_fetch_array($exec2,MYSQL_BOTH)) { echo '<tr>'; echo "<td width=100 align=center>", substr($row2['datePosted'],0,10), " </td>"; } Quote Link to comment https://forums.phpfreaks.com/topic/73094-date-display/#findComment-368626 Share on other sites More sharing options...
Cagecrawler Posted October 13, 2007 Share Posted October 13, 2007 That'll hit errors (you've used commas instead of periods). Try this: while($row2=mysql_fetch_array($exec2,MYSQL_BOTH)) { echo'<tr>'; echo"<td width=100 align=center>".substr('$row2[datePosted]',0,10)."</td>"; } Quote Link to comment https://forums.phpfreaks.com/topic/73094-date-display/#findComment-368628 Share on other sites More sharing options...
redarrow Posted October 13, 2007 Share Posted October 13, 2007 why not do it this way? while($row2=mysql_fetch_array($exec2,MYSQL_BOTH)) { //Date $date=substr($row2["datePosted"],0,10); echo '<tr>'; echo "<td width=100 align=center>$date</td>"; } Quote Link to comment https://forums.phpfreaks.com/topic/73094-date-display/#findComment-368631 Share on other sites More sharing options...
Rithiur Posted October 13, 2007 Share Posted October 13, 2007 That'll hit errors (you've used commas instead of periods). Try this: No, it doesn't. Language construct "echo" takes any number of arguments, separated by comma. Thus using something like "echo 'foo', 'bar';" will output "foobar". This is in fact better than using the concatenation operator (dot), because the PHP does not have to first combine the string before outputting them. In addition, your code wont work as intended, because you put the variable inside single quotes, and variables are not parsed inside single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/73094-date-display/#findComment-368636 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.