per1os Posted May 8, 2007 Share Posted May 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/page/2/#findComment-248432 Share on other sites More sharing options...
Barand Posted May 8, 2007 Share Posted May 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/page/2/#findComment-248434 Share on other sites More sharing options...
Trium918 Posted May 8, 2007 Author Share Posted May 8, 2007 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. ?> Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/page/2/#findComment-248445 Share on other sites More sharing options...
Barand Posted May 8, 2007 Share Posted May 8, 2007 That code does not echo anything to the screen Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/page/2/#findComment-248448 Share on other sites More sharing options...
Trium918 Posted May 8, 2007 Author Share Posted May 8, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/page/2/#findComment-248452 Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 A stupid question, but are you sure the output page is being included and session_start() is at the top of the page? Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/page/2/#findComment-248460 Share on other sites More sharing options...
Trium918 Posted May 8, 2007 Author Share Posted May 8, 2007 A stupid question, but are you sure the output page is being included and session_start() is at the top of the page? Yes, the member page is where the login form is submitted to. Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/page/2/#findComment-248469 Share on other sites More sharing options...
Barand Posted May 8, 2007 Share Posted May 8, 2007 Does that page contain a "session_start()" at the top? Sorry, didn't see these posts on the next page Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/page/2/#findComment-248472 Share on other sites More sharing options...
Trium918 Posted May 8, 2007 Author Share Posted May 8, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/page/2/#findComment-248512 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.