ctcp Posted August 4, 2009 Share Posted August 4, 2009 <?php $results = mysql_query("SELECT * FROM table WHERE type = '$type' and options = 'Yes' and topic LIKE '%". $query ."%' ORDER BY date DESC LIMIT $page, $limit"); while ($data = mysql_fetch_array($results)) { ?> <?=$data["date"]?> <? } ?> in my DB i got colum timestamps now i see my time like this 2009-08-04 09:50:35 how to view like this 09/08/04 and how to view if its today view today or yesterday thank you for help Quote Link to comment https://forums.phpfreaks.com/topic/168815-solved-prin-time/ Share on other sites More sharing options...
Maq Posted August 4, 2009 Share Posted August 4, 2009 in my DB i got colum timestamps now i see my time like this 2009-08-04 09:50:35 how to view like this 09/08/04 You can let MySQL handle this with DATE_FORMAT. and how to view if its today view today or yesterday I'm not sure what you mean, could you clarify? Quote Link to comment https://forums.phpfreaks.com/topic/168815-solved-prin-time/#findComment-890667 Share on other sites More sharing options...
MatthewJ Posted August 4, 2009 Share Posted August 4, 2009 <?php $data['date'] = "2009-08-04 09:50:35"; $display = date('y/m/d', strtotime($data['date'])); if($display == date('y/m/d', time())) { $display = "Today"; } elseif($display == date('y/m/d', (time() - 86400))) { $display = "Yesterday"; } echo $display ?> Like Maq said, DATE_FORMAT from the database is probably faster for the first part but this should work. Quote Link to comment https://forums.phpfreaks.com/topic/168815-solved-prin-time/#findComment-890670 Share on other sites More sharing options...
ctcp Posted August 4, 2009 Author Share Posted August 4, 2009 <?php $data['date'] = "2009-08-04 09:50:35"; $display = date('y/m/d', strtotime($data['date'])); if($display == date('y/m/d', time())) { $display = "Today"; } elseif($display == date('y/m/d', (time() - 86400))) { $display = "Yesterday"; } echo $display ?> Like Maq said, DATE_FORMAT from the database is probably faster for the first part but this should work. thanks mate for your help but now i see only Today not working good maybe here need change? $data['date'] = "2009-08-04 09:50:35"; add my server time? Quote Link to comment https://forums.phpfreaks.com/topic/168815-solved-prin-time/#findComment-890679 Share on other sites More sharing options...
MatthewJ Posted August 4, 2009 Share Posted August 4, 2009 I just added the line to have something to work with... you should be able to figure out where to put it within your code, or you need to post the rest of your code. <?php $results = mysql_query("SELECT * FROM table WHERE type = '$type' and options = 'Yes' and topic LIKE '%". $query ."%' ORDER BY date DESC LIMIT $page, $limit"); while ($data = mysql_fetch_array($results)) { $data['date'] = date('y/m/d', strtotime($data['date'])); if($data['date'] == date('y/m/d', time())) { $data['date'] = "Today"; } elseif($data['date'] == date('y/m/d', (time() - 86400))) { $data['date'] = "Yesterday"; } echo $data["date"]; } ?> I think that should work Quote Link to comment https://forums.phpfreaks.com/topic/168815-solved-prin-time/#findComment-890683 Share on other sites More sharing options...
ctcp Posted August 4, 2009 Author Share Posted August 4, 2009 <?php //$data['date'] = "2009-08-04 09:50:35"; $display = date('y/m/d', strtotime($data['date'])); if($display == date('y/m/d', time())) { $display = "Today"; } elseif($display == date('y/m/d', (time() - 86400))) { $display = "Yesterday"; } echo $display ?> this working fine for me .. Quote Link to comment https://forums.phpfreaks.com/topic/168815-solved-prin-time/#findComment-890685 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.