473,320 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DateDiff problem on different servers

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(subfolde r.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.Dat eLastModified,
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>


Jul 19 '05 #1
4 4070
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.


"CJM" <cj*****@yahoo.co.uk> wrote in message
news:eW**************@TK2MSFTNGP09.phx.gbl...
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(subfolde r.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.Dat eLastModified,
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>

Jul 19 '05 #2
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
"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message
news:uc**************@TK2MSFTNGP10.phx.gbl...
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.

Jul 19 '05 #3
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.

Jul 19 '05 #4
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

"Jacob Yang [MSFT]" <ji***@online.microsoft.com> wrote in message
news:$S**************@cpmsftngxa06.phx.gbl...
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.

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tim::. | last post by:
I am having some difficulties with the function Datediff! I am trying to calculate the number of days between two given date E.G: Number days between 03-05-2004 and 05-05-2004 = I am using the...
8
by: inamori | last post by:
I face that problems 07/01/2003 06/30/2006 ---------> it should be 3 01/01/2003 02/28/2005 --------->could i get 2 years and 2 months 01/01/2003 03/01/2005 ...
4
by: John Smith | last post by:
Hi, I'm having trouble working out the best way of calculating the time difference between two times on the same day. The example I have found does return the hours (in this case 8) but forgets...
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
5
by: mcbill20 | last post by:
Hello all. I have a really basic question that I hope someone has a better answer for. I apologize in advance-- I know this is probably a really basic question but I am used to Oracle rathern than...
7
by: Dean Earley | last post by:
I have the following code to get the number of seconds into a day given a date/time value: TValS = DateDiff("s", DateValue(StillDate), StillDate) StillDate is #04/05/2006 21:03:52#, and...
2
by: OdAwG | last post by:
Hello Again Access GURU's, Need some help with Conditional Formatting and datediff. What I am trying to do is the following: I have three text boxes with dates in them and what I want to do...
9
by: StevoNZ | last post by:
Hi, I am a little stuck with a query I am trying to build. Attemting to calculate the delivery time for a material. I have managed to utilise the DateDiff function, but have some additional...
9
geraldinegrieve
by: geraldinegrieve | last post by:
I have a table in access that holds data on vehicle there are 3 fields holding dates on MOT, Tax and Insurance renewal I am looking for 3 different messages on opening if date of any is within next 2...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.