endouken Posted March 30, 2011 Share Posted March 30, 2011 Hey guys & gals, i have the following code: <?php $date= $_SESSION['date']; echo $date; ?> Which is an echo of an earlier page: <?php $_SESSION['date'] = date("c")?>; How do i format the echo of the first quote code? At present it echo's like so... 2011-03-30T15:43:43+01:00 ...which although is useful for back office purposes, not so easy on the eye for the customer. How can i format so it's like DATE-MONTH-YEAR? I have googled this and there are examples, but none for when echoing a $_SESSION which is where i'm falling flat on my face. I tried this: but it doesn't work :-( echo $startdate ("F j, Y") Thanks in advance to all who read and reply Quote Link to comment https://forums.phpfreaks.com/topic/232180-formating-the-echo-of-a-session-timestamp/ Share on other sites More sharing options...
xangelo Posted March 30, 2011 Share Posted March 30, 2011 You're almost there. Try this: <?php echo date('F j, Y',$_SESSION['date']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/232180-formating-the-echo-of-a-session-timestamp/#findComment-1194371 Share on other sites More sharing options...
endouken Posted March 30, 2011 Author Share Posted March 30, 2011 You're almost there. Try this: <?php echo date('F j, Y',$_SESSION['date']); ?> Thanks. That Echoed: January 1, 1970 So almost worked. I know the $_SESSION['date'] is OK - as underneath i have echo $_SESSION['date'] just to check... Any further thoughts? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/232180-formating-the-echo-of-a-session-timestamp/#findComment-1194374 Share on other sites More sharing options...
ManiacDan Posted March 30, 2011 Share Posted March 30, 2011 <?php echo date('F j, Y', strtotime($_SESSION['date'])); Quote Link to comment https://forums.phpfreaks.com/topic/232180-formating-the-echo-of-a-session-timestamp/#findComment-1194379 Share on other sites More sharing options...
endouken Posted March 30, 2011 Author Share Posted March 30, 2011 <?php echo date('F j, Y', strtotime($_SESSION['date'])); Perfect, missing that damned strtotime - many thanks! *bows down to your greatness* Quote Link to comment https://forums.phpfreaks.com/topic/232180-formating-the-echo-of-a-session-timestamp/#findComment-1194381 Share on other sites More sharing options...
ManiacDan Posted March 30, 2011 Share Posted March 30, 2011 You could avoid this entire problem by using the proper format for date() on the first page that you set this variable on. There's no reason to set $_SESSION['date'] to a formatted string you have no intention of using, only to convert it back to a timestamp and then into another formatted string later on. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/232180-formating-the-echo-of-a-session-timestamp/#findComment-1194404 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.