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 trial

PHP Build a Simple PHP Application Getting Started with PHP Your First PHP File

derek medeiros
derek medeiros
2,614 Points

php 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
Tong Vang
9,926 Points

Make sure the file extension is php. Apache won't read it unless it is php. I had the same problem.

jcrocamonde
jcrocamonde
3,419 Points

Your doctype is very strange, never have seen that before. why dont you just put <!DOCTYPE html> ? it is new html 5.

derek medeiros
derek medeiros
2,614 Points

its just the default set from dreamweaver

derek medeiros
derek medeiros
2,614 Points

i tried it in another browser and it worked fine, must just be a chrome issue

That 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
derek medeiros
2,614 Points

i gave the month, day and year format, no dice either.

Something 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?

Oh 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
derek medeiros
2,614 Points

tried 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

LOL, ok the last question then, are you even on a Linux server and not a Windows server?

Gotchya. Odd. Try this for shits and giggles <?php echo date("r"); ?>

Can you take out all your markup and just put what I have put? Do you even have HTML markup?

derek medeiros
derek medeiros
2,614 Points

took 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?

Sure did all of my instances of it

derek medeiros
derek medeiros
2,614 Points

haha, thats amazing!! oh well, def some quirk on my end, i appreciate ur help. thanks

No worries. Enjoy!

derek medeiros
derek medeiros
2,614 Points

the 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

Ah you didn't have the engine on. Gotta have the engine on. Doh! Good find.