Jump to content

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

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.