Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Displaying dates

I created the following code to display 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:

<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>

David Watts
Wednesday, December 24, 2003

*  Recent Topics

*  Fog Creek Home