HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
archiving and displaying yesterdays date
Post new topic   Reply to topic    HTML Help Forum Index -> HTML Tools
View previous topic :: View next topic  
Author Message
wx_girl



Joined: 26 Feb 2008
Posts: 9

PostPosted: Mon Jul 28, 2008 6:11 am     archiving and displaying yesterdays date Reply with quote

I have looked online and can't find anything on how to display yesterdays date on a webpage. I am making pages that display date but the data is a day old and want to display the date for which the data corresponds. I'm not sure how to do this for I have only found code to display the current date and don't know how it will need to be written to adjust for month to month changes. I will eventually need to have pages for archives which display two and even three days ago data and would like the date stamp to correspond.

Please let me know if you can help!
Straystudio



Joined: 14 Apr 2008
Posts: 264
Location: Nord Italy

PostPosted: Mon Jul 28, 2008 1:34 pm     Previous days live date Reply with quote

Now it is late here in Italy, let me submit a sample I quickly made on now, handling just days of week; so, the Reader can easily understand my reasoning, if less things are mixed up.

Since new Date().getDay() returns a number (integer), I do Idea "this number" minus ... -1 -2 -3 depending on how much You have to go back.

The resulting number, takes an item from an Array listed as that number.

if / else statement takes in account the integer when would go under zero; as a result, a well rotating list turns out.

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Previous Date</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<script type="text/javascript">

var weekly = new Array(7);

weekly[0] = "Sunday";
weekly[1] = "Monday";
weekly[2] = "Tuesday";
weekly[3] = "Wednesday";
weekly[4] = "Thursday";
weekly[5] = "Friday";
weekly[6] = "Saturday";

function calcDate() {
   if((new Date().getDay()-1)<0) {
      yesterday = 6
      } else {
      yesterday = (new Date().getDay()-1)
        };
 document.getElementById("dateRef").value=weekly[yesterday];
 }
 
</script>
 

</head>
<body bgcolor="#777777" text="#ffffff" onLoad='calcDate();'>


<table height="100%" border="0" width="100%"><tr>
 <td bgcolor="" align="left" valign="">
 
 </td>
 </tr><tr>
 <td height="100%" bgcolor="" align="center" valign="middle">
 
 <table height="100%" border="0" width=""><tr>
  <td bgcolor="" align="left" valign="">
    <span style="font-family: Helvetica, Arial; font-size:16px;"><b>Yesterday :</b><br />
    <br /></span>
    <input id="dateRef" type="text" size=""
     style="background-color:#ffffaa; font-family:; font-size:14px; color: #0000ff; padding-left: 14px;" />
  </td></tr>
 </table>
 
 </td></tr>
 </table>


</body>
</html>

Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> HTML Tools All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial