DateDiff problem on different servers

C

CJM

I have an ASP page that lists files and folders in a directory. I'm using a
cookie to record the last time this page was visited, and I intend to show
links that are created/modified from that date minus 30mins to the
present... eg effectively new and modified files:

If DateDiff("n", subfolder.DateLastModified, sLastVisit ) < 30 Then.... etc

On my test machine this mechanism works OK, but on the live server (Win2k,
IIS5) I get some funny behaviour.

I create a new folder, and run the page. The value this expression returns
on XP is 0 and on Win2K is 43200. Refreshing every minute...on XP the value
increases, 1,2,3 etc... On Win2k, it decreases, 43200,43199,43198 etc....
Folders created days ago have values like 37415

The file list is similar:

If DateDiff("n", file.DateLastModified, sLastVisit ) < 30 Then etc....

On the Win2k m/c, a new file returns 43200 again...

Am I missing something?? Do the DateDiff functions behave differently on
different servers (ie different versions of IIS)?

Help!

Thanks

Chris




Bigger Code Snippet (some key settings are stored in an include file):

<%@ Language=VBScript %>
<%
Option Explicit
Response.Expires = 0

Dim folderspec, fso, fold, subfolder, files, file, subfld
Dim sFilter, sStartFolder, sStartPath, sTitle, sContact
Dim aDirs, i, j , sLink
Dim sLastVisit, sCookie, sDateClass, sMaxDiff

'Read LastVisit cookie
sLastVisit = Request.Cookies.Item("QADocs")("LastVisit")
If sLastVisit = "" Then
'sLastVisit = FormatDateTime(Now(),VBShortDate)
sLastVisit = Now()
End If

Response.Write sLastVisit
'Set/Update Cookie
'Response.Cookies("sCookie")("LastVisit") = FormatDateTime(Now(),
VBShortDate)
Response.Cookies.Item("QADocs")("LastVisit") = Now()

%>
<!-- #include file="config.asp" -->
<%

'Recover subfolder name if available
subfld = Request.Querystring("sub")
subfld = subfld & "/"

'create full folder path
folderspec = Replace(sStartPath & subfld, "/", "\")

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><%=sTitle%></title>
<link type='text/css' rel='stylesheet' href='Quality.css'>
</head>
<body>
<div id='header'>
<h2><%=sTitle%></h2>
</div>
<div id='outer'>
<p>Note: Files or folders that have been added or modified since your last
visit have their dates shown <span class="new">like this.</span></p>
<table id='tbls'>
<tr id="breadcrumbs">
<td colspan="2">
<%

Response.Write "<a href='./quality.asp'>" & sStartFolder & "</a>"

aDirs = Split(subfld,"/")
For i = 1 to UBound(aDirs)
Response.Write " > <a href='"

sLink = ""
For j = 1 to i
sLink=sLink & "/" & aDirs(j)
Next
Response.Write "./quality.asp?sub=" & sLink

Response.Write "'>" & aDirs(i) & "</a>"
Next

%>
</td>
</tr>
<tr>
<td>
<!-- Folders table -->
<table class="fld">
<colgroup class="lhs" />
<colgroup class="rhs" />
<tr>
<td class="title">Folder Name</td>
<td class="title">Last Modified</td>
</tr>
<%

'Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")

'Loop through Folders
Set fold = fso.GetFolder(folderspec)
for each subfolder in fold.subFolders
'ignore system or hidden folders - signified by "_"
If Left(subfolder.name,1) <> "_" Then
If DateDiff("n", subfolder.DateLastModified, sLastVisit ) < sMaxDiff Then
sDateClass = "new"
Else
sDateClass = ""
End if
%>
<tr>
<td><a class="folder"
href='quality.asp?sub=<%=subfld &
subfolder.name%>'><%=subfolder.name%>...</a></td>
<td
class="<%=sDateClass%>"><%=FormatDateTime(subfolder.DateLastModified,
VBShortDate)%><%= "..." & DateDiff("n", subfolder.DateLastModified,
sLastVisit)%></td>
</tr>
<%
End if
next
%>
</table>
</td>
<td>
<!-- Files table -->
<table class="fil">
<colgroup class="lhs" />
<colgroup class="rhs" />
<tr>
<td class="title">File Name</td>
<td class="title">Last Modified</td>
</tr>
<%
'Loop through Files
set files = fold.files
for each file in files
If Instr(1, sFilter, lcase(right(file.name,3))) Then
If DateDiff("n", file.DateLastModified, sLastVisit ) < sMaxDiff Then
sDateClass = "new"
Else
sDateClass = ""
End if
%>
<tr>
<td><a class="file" href='.<%=subfld &
file.name%>'><%=file.name%></a></td>
<td
class="<%=sDateClass%>"><%=FormatDateTime(file.DateLastModified,
VBShortDate)%><%= "..." & DateDiff("n", file.DateLastModified,
sLastVisit )%></td>
</tr>
<%
End if
Next
%>

</table>
</td>
</tr>
</table>
</div>

<p>If you have any queries or you think this page is not functioning
correctly contact <%=sContact%>.</p>

</body>
</html>
 
A

Aaron Bertrand - MVP

What does sLastVisit look like? This is one of the dangers of using
regional date formats, like dd/mm/yyyy or mm/dd/yyyy. When you run code
that relies on British format (dd/mm/yyyy) on a machine set up for US
English, you're going to get some funny behavior, for sure.

Wait until 2003-09-13, that's when code should start breaking on you. If
you want to fix it in the meantime, use an ISO standard date format instead
of a regional one.
 
C

CJM

As ever, you are quite correct. I'll convert my dates to ISO format. Well,
I've already started actually.

However, I'm afraid this is a side issue. The problem remains.

Well I'm off on my hols for a week... I guess I'll pick this up again when I
get back....!

Cheers

Chris
 
J

Jacob Yang [MSFT]

Hi CJM,

I should say this is a weird issue. This kind of problem is seldom reported
before.

I tried the following code on my side.

---------fso.vbs-------
dim filespec
filespec = "Noname1.html"

ShowFileAccessInfo filespec

Function ShowFileAccessInfo(filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = UCase(filespec) & "<BR>"
s = s & "Created: " & f.DateCreated & "<BR>"
s = s & "Last Accessed: " & f.DateLastAccessed & "<BR>"
s = s & "Last Modified: " & f.DateLastModified

dim sLastVisit

sLastVisit = f.DateLastModified - 1 ' set the sLastVisit to one day
before Now.

WScript.Echo DateDiff("n", f.DateLastModified, sLastVisit )

'ShowFileAccessInfo = s
End Function
--------------------------------

It works correctly on both Win2000 and WinXP. Please test my code on your
side. I certainly appreciate your time.

Best regards,

Jacob Yang
Microsoft Online Partner Support
<MCSD>
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
C

CJM

Jacob,

Thanks for your reply. Soirry for the delay, I've been away...

I tried your code and it appears to work fine on both XP and Win2K machines.

I'm going to follow Aarons advice and convert my dates to ISO format at the
system boundaries, and as part of this I'll revisit my code. If I'm still
suffering problems, I'll resubmit my query.

Thanks for your help.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top