bravo14 Posted July 2, 2008 Share Posted July 2, 2008 Hi all The date format in the mysql database is yyyy-mm-dd and I want to display the date dd-mmm-yyyy I have tried using the following code after having a look at other sites echo ('<tr><td>'.$row[Date].(j-M-Y)'</td><td><b>Yardley</b></td>'); and I am getting the following error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/fhlinux147/y/yardleyheroes.co.uk/user/htdocs/fixtures.php on line 59 Can anyone give me any pointers Quote Link to comment https://forums.phpfreaks.com/topic/112986-solved-date-format/ Share on other sites More sharing options...
DarkWater Posted July 2, 2008 Share Posted July 2, 2008 1) You need to use the DATE_FORMAT() MySQL function on your query. What type is the column in the DB? 2) Use ' ' around your array keys please... Quote Link to comment https://forums.phpfreaks.com/topic/112986-solved-date-format/#findComment-580380 Share on other sites More sharing options...
br0ken Posted July 2, 2008 Share Posted July 2, 2008 Is this what you want? <?php echo "<tr><td>".date("j-M-Y", $row[Date])."</td><td><b>Yardley</b></td>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/112986-solved-date-format/#findComment-580412 Share on other sites More sharing options...
DarkWater Posted July 2, 2008 Share Posted July 2, 2008 date() expects a timestamp, br0ken. Quote Link to comment https://forums.phpfreaks.com/topic/112986-solved-date-format/#findComment-580414 Share on other sites More sharing options...
br0ken Posted July 2, 2008 Share Posted July 2, 2008 date() expects a timestamp, br0ken. I assumed he'd stored a timestamp in the database and that's what he was retrieving... Quote Link to comment https://forums.phpfreaks.com/topic/112986-solved-date-format/#findComment-580423 Share on other sites More sharing options...
DarkWater Posted July 2, 2008 Share Posted July 2, 2008 "The date format in the mysql database is yyyy-mm-dd..." =X I think he used a DATE or DATETIME. It would be helpful if he posted. Quote Link to comment https://forums.phpfreaks.com/topic/112986-solved-date-format/#findComment-580430 Share on other sites More sharing options...
Barand Posted July 2, 2008 Share Posted July 2, 2008 ... and the required format is "dd-mmm-yyyy", not "d-mmm-yyyy". So echo "<tr><td>".date("d-M-Y", strtotime($row['Date']))."</td><td><b>Yardley</b></td>"; @br0ken, When was "yyyy-mm-dd" a unix timestamp? No need to assume, read the first post, first sentence Quote Link to comment https://forums.phpfreaks.com/topic/112986-solved-date-format/#findComment-580433 Share on other sites More sharing options...
bravo14 Posted July 3, 2008 Author Share Posted July 3, 2008 Sorry guys should have said the field is a date field not datetime does that make any difference to what I am trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/112986-solved-date-format/#findComment-580697 Share on other sites More sharing options...
Barand Posted July 3, 2008 Share Posted July 3, 2008 Date field is fine. Quote Link to comment https://forums.phpfreaks.com/topic/112986-solved-date-format/#findComment-580942 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.