would love some help with this php script using the date fun

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pocket2012
Forum Newbie
Posts: 3
Joined: Wed Jun 20, 2012 8:46 am

would love some help with this php script using the date fun

Post by pocket2012 »

Hi- I would love some help with this php script using the date function. We would like to see is today's date followed by the date of archived they just clicked on -- sort of like tellin g the person, "Today is June 20, 2012. The archived story you are reading is May 31, 2009".

Right now what we are seeing as a result of this is
June 20, 2012090531

Not sure why we are unable to get the May 31, 2009 in the same format. Also, as a newbie, it would be so helpful if you would also help put in the words for me "archived story you are reading is:" followed by the archive date.

Thanks so much in advance for your expertise and time.

Code: Select all


<?php $var1 = $_GET['vname'];
$var2=date('F d Y', strtotime($var1));
echo $var2;
echo $var1; //this is date of archive
?>

[php]
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: would love some help with this php script using the date

Post by Celauran »

You're passing garbage to the strtotime() function, which is why you're getting unexpected results.
pocket2012
Forum Newbie
Posts: 3
Joined: Wed Jun 20, 2012 8:46 am

Re: would love some help with this php script using the date

Post by pocket2012 »

It would be helpful if you expanded on your statement.. I am new to this.
perhaps something to show how it would work and how we would not be passing garbage? thanks.
pocket2012
Forum Newbie
Posts: 3
Joined: Wed Jun 20, 2012 8:46 am

Re: would love some help with this php script using the date

Post by pocket2012 »

Got help from a friend here at work and wanted to share for those that may have the same problem. This worked:

<?php $var1 = $_GET['vname'];
$var2=date('F d Y', strtotime($var1));
{
print " <span style=\"color:#009D57;\">&nbsp; Today: </span>"; }
echo $var2;
{
print " <span style=\"color:#996633;\">&nbsp; Archive Date: </span>"; }
list($year,$month,$day) = str_split($var1, 2);
echo date('F d, Y', mktime(0,0,0,$month,$day,$year));
?>
Post Reply