Jump to content

Recommended Posts

  <?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

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/168815-solved-prin-time/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/168815-solved-prin-time/#findComment-890667
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/168815-solved-prin-time/#findComment-890670
Share on other sites

<?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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/168815-solved-prin-time/#findComment-890679
Share on other sites

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/168815-solved-prin-time/#findComment-890683
Share on other sites

<?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 ..

 

Link to comment
https://forums.phpfreaks.com/topic/168815-solved-prin-time/#findComment-890685
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.