/    Sign up×
Community /Pin to ProfileBookmark

Auto-recognise date on a website, use the date to build links

What I’m looking to do is set up a blog with a new HTML page for each day.

I’d like to be able to upload multiple blogs in one go, i.e. load all pages for the coming week. When visitors access the site, they should see on index.html the entry for that particular day (i.e. the site will recognise that it is Tuesday and show Tuesday’s entry, even though I’ve uploaded posts until Friday).

There should then be links to ‘previous day’ and (on everything other than today’s post), ‘next day’, which should again be automatically worked out.

Is there any way of doing this in HTML / Javascript or something relatively simple which won’t require a server-side d/b?

All help greatfully appreciated, thanks!

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@saturday79authorApr 27.2008 — Hi,

I've tried putting some code together, but it's not working. I know I'm doing something daft somewhere, pointers appreciated!

In the <head> I've put the following:
<i>
</i>&lt;script TYPE="text/javascript"&gt;
&lt;!--
var pDate= "20080401";

function checkDate(pDate){
var now=new Date();
var yy= now.getYear();
Tyy = yy.toString();
var mm= now.getMonth();
Tmm = mm.toString();
var dd= now.getDate();
Tdd = dd.toString();
var todayDate= Tyy+Tmm+Tdd;
}
//--&gt;
&lt;/script&gt;


I then have the following <body> tag:
<i>
</i>&lt;body background="bgsq.jpg" onload="checkDate()"&gt;


Further down the page, I have:
<i>
</i>&lt;td&gt;
&lt;script TYPE="text/javascript"&gt;
&lt;!--
if (todayDate &gt; pDate){
document.write("&lt;b&gt;&lt;a href="link.html"&gt;next day &amp;gt;&lt;/a&gt;&lt;/b&gt;");
}
//--&gt;
&lt;/script&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;/td&gt;


Not sure why this doesn't show, bearing in mind I think todayDate should be 20080427 and that I've set pDate to 20080401.

Thanks
Copy linkTweet thisAlerts:
@JMRKERApr 27.2008 — While I not exactly sure what you want to do with the information

This should get you closer to your goal:
[code=php]
<html>
<head>
<title>Dated Files</title>
<script type="text/javascript">

var todayDate = '';
function checkDate(pDate){
var now=new Date();
var yy= now.getFullYear().toString();
var mm= (now.getMonth()+1).toString(); if (mm.length < 2) { mm = '0'+mm; }
var dd= now.getDate().toString(); if (dd.length < 2) { dd = '0'+dd; }
todayDate= yy+mm+dd;
var msg = 'Today:'+todayDate+'npDate:'+pDate;
if (todayDate > pDate) { alert(msg+'n>>>');
return true;
} else { alert(msg+'n<<<');
return false;
}
}
</script>
</head>
<body>
<table border="1">
<tr>
<td>
<div id="Tdate">
<a href="#"
onClick="if(checkDate('20080401')){alert('To go to: ')}else{alert('No go! ')}">
next day &gt;&gt; </a>
</div>
</td>
</tr>
</table>
</body>
</html>
[/code]

Alerts are for testing only.

Modify them to goto or not notgoto your HTML files.?
Copy linkTweet thisAlerts:
@saturday79authorMay 04.2008 — sorry, i'm still having issues, not sure what's going wrong.

i have stripped my page down and am basically just trying to get the value of 'todayDate' to print on the page. ultimately, i want to compare 'todayDate' with the hard-coded 'pDate' to work out whether to show a 'next day' link or not on a blog.

can anyone point me in the right direction to get todayDate to print on this page? (NB. mm / yy etc. also do not print if i swap them in for todayDate)

thanks!

<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;test page&lt;/title&gt;

&lt;script type="text/javascript"&gt;
&lt;!--
var todayDate = '';
var pDate= "20080401";

function checkDate() {
var now=new Date();
var yy= now.getFullYear().toString();
var mm= (now.getMonth()+1).toString(); if (mm.length &lt; 2) { mm = '0'+mm; }
var dd= now.getDate().toString(); if (dd.length &lt; 2) { dd = '0'+dd; }
todayDate= yy+mm+dd;
}
//--&gt;
&lt;/script&gt;

&lt;/head&gt;

&lt;body onload="checkDate()"&gt;

&lt;center&gt;
&lt;p&gt;&lt;font style="font-family:tahoma,arial;font-size:12pt;color:#333333"&gt;&lt;br&gt;&lt;/font&gt;&lt;/p&gt;
&lt;table align="center" width="780" bgcolor="#EEEEEE"&gt;

&lt;tr&gt;
&lt;td width="780" align="top" valign="top" colspan="4"&gt;
&lt;p align="left"&gt;&lt;font style="font-family:tahoma,arial;font-size:8pt;color:#999999"&gt;
Normal text here. todayDate should appear on following line&lt;br&gt;
&lt;script language="JavaScript" type="text/javascript"&gt;
document.write(todayDate);
&lt;/script&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td width="90"&gt;&lt;/td&gt;
&lt;td width="220" height="20" align="top" valign="top"&gt;&lt;p align="right"&gt;&lt;font

style="font-family:tahoma,arial;font-size:8pt;color:#999999"&gt;
&lt;b&gt;&lt;a href="link.html"&gt;&amp;lt; previous day&lt;/a&gt;&lt;/b&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="160" height="20" align="top" valign="top"&gt;&lt;p align="center"&lt;font

style="font-family:tahoma,arial;font-size:8pt;color:#999999"&gt;
&lt;b&gt;[Enter date here]&lt;/b&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="310" height="20" align="top" valign="top"&gt;&lt;p align="left"&gt;&lt;font

style="font-family:tahoma,arial;font-size:8pt;color:#999999"&gt;
&lt;b&gt;&lt;a href="link2.html"&gt;next day &amp;gt;&lt;/a&gt;&lt;/b&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @saturday79 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...