Web Hosting Talk







View Full Version : generate date link in PHP


ieee488
06-23-2005, 08:17 PM
Every Thursday, a website I link to creates a new webpage of discounts. For example, today is Thursday June 23, so the filename is 2005-06-23.html.

What I want to do is to change the link on my page to automatically update when it is Thursday so that it is <a href="http://www.otherwebsite.com/discounts/2005-06-23.html">link</a>
and next Thursday it would be
<a href="http://www.otherwebsite.com/discounts/2005-06-30.html">link</a>
and so forth.

I hope I am explaining it clearly.

What would be a good way of doing this in PHP?

error404
06-24-2005, 12:26 AM
<a href="http://www.otherwebsite.com/discounts/<?php echo date('Y-m-d'); ?>.html">link</a>


I think that's what you want..

ieee488
06-24-2005, 08:10 AM
thanks
but the link should not be of the current date
which is what I think your example does

the link should change every Thursday but stay unchanged
until the next Thursday

coderdan
06-24-2005, 08:38 AM
change error404's code a bit
date('Y-m-d',strtotime('last Thursday',strtotime('+1 day')));

ieee488
06-24-2005, 10:14 AM
Coderdan,


Thanks!

In your code if it isn't a Thursday then you get the timestamp of the previous Thursday.

But I'm not sure how it is adjusting so that if it is a Thursday
then you just get the timestamp.

I'm a beginner with PHP.

coderdan
06-24-2005, 10:45 AM
That is why a day is added first. It has no influence on the result except if the day is Thursday.

ieee488
06-24-2005, 02:15 PM
ingenious!

there I was going through all sorts of gyrations, and it was that simple.

thanks again.