Jump to content

Formating the echo of a session timestamp


endouken

Recommended Posts

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 :)

 

 

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!

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

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.