Contact
Sitemap
Download
Buy online
Imprint
Home

How to display either just the Filed date or both the Filed / Modified date [by David Watts]

The following code displays either just the Filed date (if the article hasn't been modified), or both the Filed date and the modified date if they are different.

The resulting text is either

Published Sun 12/21/03 02:57 PM

or

First published Sat 10/11/03 09:44 PM. Updated Sun 12/21/03 03:18 PM

Just insert this text into your article or template (or by the way of a variable):

<SCRIPT LANGUAGE="JavaScript">
<!--
{$setDateTimeFormat "English" "MMMM dd, yyyy" "HH:mm:ss"$} // the format that the Date method requires
filedDate=new Date("{$ .filedDate $}")
modifiedDate=new Date("{$ .modifiedDate $}")
{$setDateTimeFormat "English" "ddd M/dd/yy" "hh:mm tt"$} // the format to print
with (document) {
  if (Date.parse(filedDate) == Date.parse(modifiedDate))
      write("<p>Published {$ .filedDate $} {$ .filedTime $}</p>")
  else
      write("<p>First published {$ .filedDate $} {$ .filedTime $}. Updated {$ .modifiedDate $} {$ .modifiedTime $}</p>")
}
//-->
</SCRIPT>

JavaScript Extensions

Copyright © 2005-2006 by telepark. All rights reserved.