Jump to content

[SOLVED] Last Visited. Weigh in Please!


Trium918

Recommended Posts

As long as it is always the same amount you can use substr.

 

<?php
$d = '20070508155335';
$d = substr($d, 0, -6);
echo date('n/d/Y', strtotime($d));
?>

 

www.php.net/substr

 

That or the substr part should be

$d = substr($d, -6); I can never remember which it should be.

That code should work perfectly well even with the time element in there. Specifying a format string with no time bits does away with it for you.

 

Barand, here is my code. It isn't working. The output

is showing up blank until I take the time off.

<?php
$sql1="SELECT last_visit FROM users WHERE user_name='$user_name'";
$result1=mysql_query($sql1);
$row=mysql_fetch_assoc($result1);
$last=$row['last_visit'];
  
//$last substr($last, 0, ;
$last = date('n/d/Y', strtotime($last));  
  
$_SESSION['last']=$last;   //use the session variable to hold the previous last visit date.

?>

That code does not echo anything to the screen

 

The echo takes place in another page.

 

<td align="left" class="genmed">
     <div class=m5a style="MaRGIN-TOP: 0px">Last 
      visited</div></td>
<td align="right" class="genmed">
      <div class=m5a 
       style="MaRGIN-TOP: 0px"><?php echo $_SESSION['last']; ?></div></td></tr>

That code should work perfectly well even with the time element in there. Specifying a format string with no time bits does away with it for you.

 

Thanks Barand, you were right! I had the Lastvisit column set

to Timestamp not NULL default NULL; I changed it back to

datetime not NULL default'0000-00-00' and it work perfectly.

 

Thanks also frost110!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.