Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Sep 20, 1999

Display Various Date Information in your ASP Pages

There are certain scenarios where you need to display the create date or the last modified date of your document. There is a "LastModified" method in the "document" object which gives you the last modified date of the HTML document under context. This method cannot be used to get the last modified date information for an ASP page because it looks for the date information on the final HTML document which gets generated after the ASP code is processed by the web server. Due to this reason "document.LastModified" method will always give you the current date time for the HTML pages that get created as a result of ASP pages.

Here is a simple method which can be used to show date related information in the ASP pages. You can use server variable "PATH_INFO" to get the relative path of the asp page an then using "MapPath" method of "Server" object you can get the complete physical path of the ASP page under process. After this use file system objects to get various date related information for the ASP page. For example: Method GetFileDateInfo() can be used to get create date, last modified date, and last accessed date information for the ASP page under process. The code following this method calls this method and writes the info to the output HTML page using "Response" object.

 
<%
Sub GetFileDateInfo(dtCreateDate, dtLastModified, dtLastAccessed)

 Dim oFileSystemObject, oFile

 ' Get the Complete path of the file using server variables 
and MapPath method strFilePath = Server.MapPath(Request.ServerVariables("PATH_INFO")) ' Create file system object to do the remaining trick Set oFileSystemObject = Server.CreateObject
("Scripting.FileSystemObject") ' Get the handle on the file Set oFile = oFileSystemObject.GetFile(strFilePath) ' Return various date info using the properties of file object dtCreateDate = oFile.DateCreated dtLastModified = oFile.DateLastModified dtLastAccessed = oFile.DateLastAccessed End Sub %> <% ' Show date information on the asp page Dim dtCreateDate, dtLastModified, dtLastAccessed GetFileDateInfo dtCreateDate, dtLastModified, dtLastAccessed Response.Write "Create Date : " & dtCreateDate & "
" Response.Write "Last Updated : " & dtLastModified & "
" Response.Write "Last Accessed : " & dtLastAccessed & "
" %>
Deepak Pant
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date