Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialderek medeiros
2,614 Pointsphp date not working
for some reason i cant get the php date function to show when the page is ran. the copyright and other stuff show up, but no date.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Shirts 4 Mike</title> </head>
<body> <h1>Shirts 4 Mike</h1> <p>Ā©<?php echo date('Y'); ?>Shirts 4 Mike</p>
</body> </html>
14 Answers
Tong Vang
9,926 PointsMake sure the file extension is php. Apache won't read it unless it is php. I had the same problem.
jcrocamonde
3,419 PointsYour doctype is very strange, never have seen that before. why dont you just put <!DOCTYPE html> ? it is new html 5.
derek medeiros
2,614 Pointsits just the default set from dreamweaver
derek medeiros
2,614 Pointsi tried it in another browser and it worked fine, must just be a chrome issue
Stef Serafin
967 PointsThat should work in Chrome. Maybe you have a setting off or something? And like Tong said make sure the file extension is PHP and not HTML or it won't show. If you want to get real fancy you could do echo date('M, d, Y');
derek medeiros
2,614 Pointsi gave the month, day and year format, no dice either.
Stef Serafin
967 PointsSomething isn't getting called right then. Are you doing this in straight PHP or are you working in WordPress or something? In the console to Chrome are you seeing/getting any errors?
Stef Serafin
967 PointsOh I think I see it. Take the semi colon out so it's just this <?php echo date("Y") ?>
and use quotes as seen here. Try that and let me know.
Examples:
<?php echo date("M, d, Y") ?>
or
<?php echo date("Y") ?>
And make sure you're clearing your cache too.
derek medeiros
2,614 Pointstried it all, lol. love trying to figure these issues out, but frustrating at same time. i even copy and pasted yours to make sure i wasnt going crazy
Stef Serafin
967 PointsLOL, ok the last question then, are you even on a Linux server and not a Windows server?
Stef Serafin
967 PointsGotchya. Odd. Try this for shits and giggles <?php echo date("r"); ?>
Stef Serafin
967 PointsCan you take out all your markup and just put what I have put? Do you even have HTML markup?
derek medeiros
2,614 Pointstook em all out, worked on IE but blank on chrome. dont think it is a code issue as much as it is a compatabilty issue,did it work for you on chrome?
Stef Serafin
967 PointsSure did all of my instances of it
derek medeiros
2,614 Pointshaha, thats amazing!! oh well, def some quirk on my end, i appreciate ur help. thanks
Stef Serafin
967 PointsNo worries. Enjoy!
derek medeiros
2,614 Pointsthe problem was that when i did a preview on DW, it was calling up the script from file location, so wasn't getting processed through xampp. once i called up by http://localhost... it worked. : ) its always the little things that get overlooked
Stef Serafin
967 PointsAh you didn't have the engine on. Gotta have the engine on. Doh! Good find.