`Karl Posted November 4, 2009 Share Posted November 4, 2009 I'm currently using this: $sql="INSERT INTO (id, modifiedon) VALUES ('',current_date)"; to save when a page has been edited. The database type is set as date. So when I call it at a later time, the format is 2009-11-02 18:32:29, etc. I was wondering how I'd go about changing this format so that it's displayed how I want it. (02/11/2009 at 18:32 GMT). But I'm a rookie at this atm, hope you understand what I'm asking. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 4, 2009 Share Posted November 4, 2009 How a date is stored has very little relation to how it is displayed. You can use PHP to display the date by using a combination of the date and strtotime functions. Ken Quote Link to comment Share on other sites More sharing options...
`Karl Posted November 4, 2009 Author Share Posted November 4, 2009 Thanks for the reply, I've looked in to them previously, but I just don't understand. I know the format I want but not how I'd manipulate the information in the database. d/m/Y at H:i GMT < The format I want. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 4, 2009 Share Posted November 4, 2009 Leave the format in the database alone. Let's say you have: <?php $ts = "2009-11-02 18:32:29"; ?> to display this, use <?php echo date('d/m/Y H:i \G\M\T',strtotime($ts)); ?> Ken Quote Link to comment Share on other sites More sharing options...
`Karl Posted November 4, 2009 Author Share Posted November 4, 2009 Okay that's pretty simple, but the date and time is dragged from the database using {$arr['datetime']}, how would that work with the $ts? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 4, 2009 Share Posted November 4, 2009 Just use $arr['datetime'] instead of $ts. Ken Quote Link to comment Share on other sites More sharing options...
`Karl Posted November 4, 2009 Author Share Posted November 4, 2009 So this should work? <?php echo date('d/m/Y H:i \G\M\T',strtotime($arr['datetime'])); ?> Because I'm receiving this Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/karl/public_html/index.php on line 80 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 4, 2009 Share Posted November 4, 2009 Is that line 80? Please show us line 80 +/- 5 lines That syntax is correct. Ken Quote Link to comment Share on other sites More sharing options...
`Karl Posted November 4, 2009 Author Share Posted November 4, 2009 <div style="border-bottom:1px; solid #21405c; background: #232323; margin: 0 12.80em 0 12.80em; text-indent:50px;"> <b><font size="2" color="#FFFFFF">{$arr['title']}</font></b><br> <div style="border-top:1px solid #21405c; text-indent: 0px; margin-left:4px; margin-right:4px;"><font size="2" color="#FFFFFF">{$arr['news']}</font></div> <div style="text-align: right; border-bottom:2px solid #21405c;"><font size="1" color="#FFFFFF"><div style="margin-right: 10px;">Posted by</font> <font size="1" color="#3d75a7">{$arr['postedby']}</font> <font size="1" color="#FFFFFF">on</font> <font size="1" color="#3d75a7"><?php echo date('d/m/Y H:i \G\M\T',strtotime($arr['datetime'])); ?></font></div></div> </div> HTML; } }else{ Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 4, 2009 Share Posted November 4, 2009 Is this in the middle of a HEREDOC string? Ken Quote Link to comment Share on other sites More sharing options...
`Karl Posted November 4, 2009 Author Share Posted November 4, 2009 Yes it is. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 4, 2009 Share Posted November 4, 2009 Then you can't use "<?php", "echo", and "?>" within it. Ken Quote Link to comment Share on other sites More sharing options...
`Karl Posted November 4, 2009 Author Share Posted November 4, 2009 I've managed to fix it, I closed the heredoc string before it, and re-opened it after. Thanks for your help Ken. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 4, 2009 Share Posted November 4, 2009 Please mark the topic as "solved" Quote Link to comment Share on other sites More sharing options...
`Karl Posted November 4, 2009 Author Share Posted November 4, 2009 Done. Quote Link to comment 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.