Jump to content

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!

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.