Page 1 of 1

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

Posted: Wed Jun 20, 2012 8:50 am
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]

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

Posted: Wed Jun 20, 2012 9:09 am
by Celauran
You're passing garbage to the strtotime() function, which is why you're getting unexpected results.

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

Posted: Wed Jun 20, 2012 9:38 am
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.

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

Posted: Wed Jun 20, 2012 9:56 am
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));
?>