CoverYourASP --> "/Date.html" --> Source

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
30 active users
236 visitors today
244 pages today
how is this done?
Tools I use

CoverYourASP
Copyright © 1999-2015 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

This page shows the actual source code used on this site. You can read the article that discusses this code here.

If this is the first CYA source code you've seen you should read this overview first.

Did you know you can download all the source code (and the database) of this site? Then get my newsletter to be emailed when I update the source code!

Please spread the word by recommending my site to your friends and colleagues!

This is JScript (server-side JavaScript), not the more common VBScript. More...

Date.asp

<!--#include file = "/include/Startup.html"-->

<%
// ============================================
// NOTE: all source code downloaded from CoverYourASP was written by
// James Shaw (unless stated otherwise), and is copyright (c) 2000-2002
// by James Shaw. You can use the code for any purpose, but do not
// publish or distribute the content in any way.
//
// See http://CoverYourASP.com/Legal.asp for up-to-date details.
// ============================================

// output relevant meta tags
Init( "Dynamic content - the time!" );

// output common top of page
Header( 'Dynamic content' );

// output page content
Content ( );

// output common bottom of page
Footer( );

// ============================================
// the content of this page
// ============================================
function Content ( )
{
   Out ( '<td valign="top" class="content">' );

      Out ( '<b>' + GetDate ( ) + '</b>' );

      Out ( '<p>This is an excellent example of how pages are generated dynamically by ASP. Look at the HTML source (use View/Source in Internet Explorer) and all that you\'ll see is the date as if the HTML was written that way.' );

      Out ( '<p>And that\'s exactly what\'s happened in fact, but rather than me writing the HTML in my editor, my ASP page has.' );
      
      Out ( '<p>You can see my actual ASP source code by clicking on the icon below.' );

      Out ( '<p><center><a href="ShowSource.asp?page=Date"><img src="images/source.gif" border=0></a></center>' );

      ShowBottomBanner()

   Out ( '</td>' );
   Out ( '<td background="/images/gx/navgap.gif" valign="top">' );

      // show rotating banners
      ShowBanners ( 1 );

   Out ( '</td>' );
}

// ============================================
// returns a formatted string containing todays time and date
// ============================================
function GetDate ( )
{
   var dateToday = new Date();
   var sDays = new Array ( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" );

   var sDate = 'Here in Atlanta it\'s ' + sDays[dateToday.getDay()] + ", ";

   // work out which suffix to append
   var nDate = dateToday.getDate();
   var nMod = nDate % 10;
   var sSuffix = "th";

   if ( nDate < 10 || nDate > 20 )
   {
      if ( nMod == 1 )
         sSuffix = "st";
      else if ( nMod == 2 )
         sSuffix = "nd";
      else if ( nMod == 3 )
         sSuffix = "rd";
   }

   // note: don't bother adding <SUP> to the suffix - it's too small
   sDate += nDate + sSuffix + " ";

   var sMonths = new Array ( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" );

   sDate += sMonths[dateToday.getMonth()];

   // now the time..
   sDate += ' at ';

   if ( dateToday.getMinutes() < 7 )
      sDate += 'just after';
   else if ( dateToday.getMinutes() < 22 )
      sDate += 'quarter past';
   else if ( dateToday.getMinutes() < 37 )
      sDate += 'half past';
   else
   {
      dateToday.setHours ( dateToday.getHours () + 1 );

      if ( dateToday.getMinutes() < 52 )
         sDate += 'quarter to';
      else
         sDate += 'just before';
   }

   sDate += ' ';

   if ( dateToday.getHours ()  == 0 )
      sDate += 'midnight';
   else if ( dateToday.getHours () < 12 )
      sDate += dateToday.getHours () + ' in the morning';
   else if ( dateToday.getHours () == 12 )
      sDate += 'midday';
   else if ( dateToday.getHours () < 18 )
      sDate += (dateToday.getHours () - 12) + ' in the afternoon';
   else
      sDate += (dateToday.getHours () - 12) + ' at night';
   
   sDate += '. (ish)';

   return sDate;
}
%>

Hopefully much of this is self-explanatory. If not, or if you see ways that I can improve the code, please drop me a line.

To see the source code for this page, click on the icon below.

Featured sponsor
My favorite resources


Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!


See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?


New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!


I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...