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 toget 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 codefollowing this method calls this method and writes the info to the outputHTML page using “Response” object.

 <%Sub GetFileDateInfo(dtCreateDate, dtLastModified, dtLastAccessed) Dim oFileSystemObject, oFile ' Get the Complete path of the file using server variables 
and MapPathmethod 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.DateLastAccessedEnd 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 & "

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles:

©2023 Copyright DevX - All Rights Reserved. Registration or use of this site constitutes acceptance of our Terms of Service and Privacy Policy.