`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. Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/ 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 Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951105 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. Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951107 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 Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951113 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? Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951115 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 Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951118 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 Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951120 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 Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951125 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{ Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951126 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 Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951127 Share on other sites More sharing options...
`Karl Posted November 4, 2009 Author Share Posted November 4, 2009 Yes it is. Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951132 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 Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951133 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. Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951135 Share on other sites More sharing options...
kenrbnsn Posted November 4, 2009 Share Posted November 4, 2009 Please mark the topic as "solved" Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951144 Share on other sites More sharing options...
`Karl Posted November 4, 2009 Author Share Posted November 4, 2009 Done. Link to comment https://forums.phpfreaks.com/topic/180300-solved-php-current_date-help/#findComment-951160 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.