By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,688 Members | 1,888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,688 IT Pros & Developers. It's quick & easy.

Another DateDiff() problem to add to the list

P: n/a
I did a group search and found hundreds of cases of problems with
DateDiff(). I read through several dozen but they didn not apply to
my situation. Not having the time to read through all of them I'm
hoping that I'll get an answer here.

The software scenario. IIS 5.0 running on Windows Server 2000. The
application is a campsite reservation system. The application starts
with a simple HTML form that people enter an arrival date and a
departure date. These two values are passed to the next page where I
want to return the sites that are open between those two dates.
Simple enough and DateDiff("d", ArrivalDate, DepartureDate) should
return what I want.

But it doesn't.

If I enter May 2nd, 2007 into the form (i.e. 5/2/2007) as the arrival
date and May 19th, 2007 (5/19/2007) as the departure date I don't get
17 days as the returned value. I get a date as if I'd entered
February 5th to May 19th and 103 days is the result returned.

I've double-checked the regional date settings on the server and they
are set for US (m/d/yyyy).

Here's a snippet of the code that I'm using:

Expand|Select|Wrap|Line Numbers
  1. dim ArrivalDate, DepartureDate, NumNights
  2.  
  3. ArrivalDate = request.form("txtArrivalDate")
  4. DepartureDate = request.form("txtDepartureDate")
  5.  
  6. NumNights = Datediff("d", cdate(ArrivalDate),cdate(DepartureDate))
  7.  
Major PITA going on here.

May 1 '07 #1
Share this Question
Share on Google+
12 Replies


P: n/a
wrote on 01 mei 2007 in microsoft.public.inetserver.asp.general:
I did a group search and found hundreds of cases of problems with
DateDiff(). I read through several dozen but they didn not apply to
my situation. Not having the time to read through all of them I'm
hoping that I'll get an answer here.

The software scenario. IIS 5.0 running on Windows Server 2000. The
application is a campsite reservation system. The application starts
with a simple HTML form that people enter an arrival date and a
departure date. These two values are passed to the next page where I
want to return the sites that are open between those two dates.
Simple enough and DateDiff("d", ArrivalDate, DepartureDate) should
return what I want.

But it doesn't.

If I enter May 2nd, 2007 into the form (i.e. 5/2/2007) as the arrival
date and May 19th, 2007 (5/19/2007) as the departure date I don't get
17 days as the returned value. I get a date as if I'd entered
February 5th to May 19th and 103 days is the result returned.

I've double-checked the regional date settings on the server and they
are set for US (m/d/yyyy).
So probably you are wrong there!!!!!!!!!!!
Here's a snippet of the code that I'm using:

Expand|Select|Wrap|Line Numbers
  1.      dim ArrivalDate, DepartureDate, NumNights
  2.      ArrivalDate = request.form("txtArrivalDate")
  3.      DepartureDate = request.form("txtDepartureDate")
  4.      NumNights = Datediff("d", cdate(ArrivalDate),cdate(DepartureDate))
  5.  
Testing/debugging will give you the answer:

<%
d1 = "5/2/2007"
d2 = "5/19/2007"
response.write "month(d1): " & month(d1) & "<br>"
response.write "month(d2): " & month(d2) & "<br>"
r = Datediff("d", cdate(d1),cdate(d2))
response.write "difference in days: " & r & "<br>"
%>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 1 '07 #2

P: n/a
To**********@gmail.com wrote:
I did a group search and found hundreds of cases of problems with
DateDiff(). I read through several dozen but they didn not apply to
my situation. Not having the time to read through all of them I'm
hoping that I'll get an answer here.

The software scenario. IIS 5.0 running on Windows Server 2000. The
application is a campsite reservation system. The application starts
with a simple HTML form that people enter an arrival date and a
departure date. These two values are passed to the next page where I
want to return the sites that are open between those two dates.
Simple enough and DateDiff("d", ArrivalDate, DepartureDate) should
return what I want.

But it doesn't.

If I enter May 2nd, 2007 into the form (i.e. 5/2/2007) as the arrival
date and May 19th, 2007 (5/19/2007) as the departure date I don't get
17 days as the returned value. I get a date as if I'd entered
February 5th to May 19th and 103 days is the result returned.

I've double-checked the regional date settings on the server and they
are set for US (m/d/yyyy).

Here's a snippet of the code that I'm using:

Expand|Select|Wrap|Line Numbers
  1. dim ArrivalDate, DepartureDate, NumNights
  2. ArrivalDate = request.form("txtArrivalDate")
  3. DepartureDate = request.form("txtDepartureDate")
  4. NumNights = Datediff("d", cdate(ArrivalDate),cdate(DepartureDate))
  5.  

Major PITA going on here.
I hope you are entering your dates in a nonambiguous format. Try
yyyy-mm-dd

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
May 1 '07 #3

P: n/a
On May 1, 12:55 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:
>
I hope you are entering your dates in a nonambiguous format. Try
yyyy-mm-dd

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

This campsite reservations system will be open to the public once it's
done. The area I live in is the midwest USA so most everyone here is
used to entering dates in mm/dd/yyyy format. The dates will get
converted to datetime fields in the SQL database though. But for now
I need to be able to allow people to enter dates in as mm/dd/yyyy, mm-
dd-yyyy, etc.

I've added a intermediary validation page that checks the date values
before passing on to the next step. After doing this I noticed some
weird things going on with the dates

- Any date, in any month, that's less than 12 is getting the month and
date switched around
- For some reason using the MonthName() function returns month names
in Finnish instead of English. O.o Why on earth would I get Finnish
instead of English? I've checked the regional settings on the server,
the PC I'm browsing/developing in, and the settings in the browsers
(Firefox 2 and IE7).

May 2 '07 #4

P: n/a
TofuTheGreat wrote on 02 mei 2007 in
microsoft.public.inetserver.asp.general:
On May 1, 12:55 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:
>>
I hope you are entering your dates in a nonambiguous format. Try
yyyy-mm-dd
Bob is right, see below.
This campsite reservations system will be open to the public once it's
done. The area I live in is the midwest USA so most everyone here is
used to entering dates in mm/dd/yyyy format. The dates will get
converted to datetime fields in the SQL database though. But for now
I need to be able to allow people to enter dates in as mm/dd/yyyy, mm-
dd-yyyy, etc.
The way he input is written by the user
should not influence way you should use the date:

d1 = request.form("date1") ' "5/17/2007"
d2 = split(d1,"/")
d3 = d2(2) & "-" & d2(0) & "-" & d2(1) ' "2007-5-17"
I've added a intermediary validation page that checks the date values
before passing on to the next step. After doing this I noticed some
weird things going on with the dates

- Any date, in any month, that's less than 12 is getting the month and
date switched around
- For some reason using the MonthName() function returns month names
in Finnish instead of English. O.o Why on earth would I get Finnish
instead of English? I've checked the regional settings on the server,
Again, probably you are wrong.
the PC I'm browsing/developing in, and the settings in the browsers
(Firefox 2 and IE7).
If this is about serverside asp-vbs code,
it has nothing to do with browser settings
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 2 '07 #5

P: n/a
TofuTheGreat wrote:
On May 1, 12:55 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:
>>
I hope you are entering your dates in a nonambiguous format. Try
yyyy-mm-dd

This campsite reservations system will be open to the public once it's
done. The area I live in is the midwest USA so most everyone here is
used to entering dates in mm/dd/yyyy format. The dates will get
converted to datetime fields in the SQL database though.
Do you think this is going to happen by magic? What datetime value is
the database supposed to convert '5/2/2007' to? You're thinking it's
supposed to automagically know that this date is m/d/yyyy vs d/m/yyyy?
But for now
I need to be able to allow people to enter dates in as mm/dd/yyyy, mm-
dd-yyyy, etc.
This will not work - believe me. Use a client-side calendar control or
three dropdowns from which the user can select month, day and year.

More reading you need to do:
http://www.aspfaq.com/show.asp?id=2313 vbscript
http://www.aspfaq.com/show.asp?id=2040 help with dates
http://www.aspfaq.com/show.asp?id=2260 dd/mm/yyy confusion
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
May 2 '07 #6

P: n/a

"TofuTheGreat" <To**********@gmail.comwrote in message
news:11**********************@y5g2000hsa.googlegro ups.com...
On May 1, 12:55 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:

I hope you are entering your dates in a nonambiguous format. Try
yyyy-mm-dd

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


This campsite reservations system will be open to the public once it's
done. The area I live in is the midwest USA so most everyone here is
used to entering dates in mm/dd/yyyy format. The dates will get
converted to datetime fields in the SQL database though. But for now
I need to be able to allow people to enter dates in as mm/dd/yyyy, mm-
dd-yyyy, etc.

I've added a intermediary validation page that checks the date values
before passing on to the next step. After doing this I noticed some
weird things going on with the dates

- Any date, in any month, that's less than 12 is getting the month and
date switched around
- For some reason using the MonthName() function returns month names
in Finnish instead of English. O.o Why on earth would I get Finnish
instead of English? I've checked the regional settings on the server,

The most likely source of regional settings under which script runs are
those of the DEFAULT user. These may not be the same as machine settings.
In XP/2003 you can tick the Default user account settings check box in the
regional options advanced tab. This will reset the DEFAULT user to use the
current machine settings.

Since most ASP runs under the anonymous user account (which doesn't usually
have a user profile of its own) the settings for the default user will be
used.

NB. ASP caches regional settings from the profile of whatever user account
happens to access the application first after a process re-start. Those
settings then stick for all ASP processing regardless of the user account
that it may run under. Therefore if you are using other forms of
authentication which map to Domain or machine users which in turn have a
profile on the server (because at some point they have logged on to it
interactively) then potentially their regional settings have been cached and
are in use by the server.
the PC I'm browsing/developing in, and the settings in the browsers
(Firefox 2 and IE7).

May 3 '07 #7

P: n/a
Anthony Jones wrote on 03 mei 2007 in
microsoft.public.inetserver.asp.general:
The most likely source of regional settings under which script runs
are those of the DEFAULT user. These may not be the same as machine
settings. In XP/2003 you can tick the Default user account settings
check box in the regional options advanced tab. This will reset the
DEFAULT user to use the current machine settings.

Since most ASP runs under the anonymous user account (which doesn't
usually have a user profile of its own) the settings for the default
user will be used.

NB. ASP caches regional settings from the profile of whatever user
account happens to access the application first after a process
re-start. Those settings then stick for all ASP processing regardless
of the user account that it may run under. Therefore if you are using
other forms of authentication which map to Domain or machine users
which in turn have a profile on the server (because at some point they
have logged on to it interactively) then potentially their regional
settings have been cached and are in use by the server.
So the only reasonable advice about regional settings is:
[speaking asp-vbs]

DO NOT trust those settings.
DO NOT trust those settings to remain as they are now.
DO NOT trust string-to-date conversions to be stable.
DO NOT use functions and defaults based on those settings.

=======================================

Make your own format functions using code and
litterals like this:

df = #2007-05-03#

m="x/Jan/Feb/Mar/Apr/May/Jun/Jul/Aug/Sep/Oct/Nov/Dec"
MonthStr = split(m,"/")

ds = day(df)&" "&MonthStr(month(df))&" "&year(df)

response.write ds & "<br>"
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 3 '07 #8

P: n/a
On May 2, 10:43 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
I've added a intermediary validation page that checks the date values
before passing on to the next step. After doing this I noticed some
weird things going on with the dates
- Any date, in any month, that's less than 12 is getting the month and
date switched around
- For some reason using the MonthName() function returns month names
in Finnish instead of English. O.o Why on earth would I get Finnish
instead of English? I've checked the regional settings on the server,

Again, probably you are wrong.
the PC I'm browsing/developing in, and the settings in the browsers
(Firefox 2 and IE7).

If this is about serverside asp-vbs code,
it has nothing to do with browser settings

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sorry but I don't see how I can be wrong about the month name coming
back in a different language? It really was coming back in a
different language. I even took a screenshot to show someone else
that didn't believe me. O.o

BTW, I only mentioned the browser settings as I thought people might
question it. If you look back I mentioned the IIS configuration.


May 4 '07 #9

P: n/a
TofuTheGreat wrote on 04 mei 2007 in
microsoft.public.inetserver.asp.general:
On May 2, 10:43 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
I've added a intermediary validation page that checks the date
values before passing on to the next step. After doing this I
noticed some weird things going on with the dates
- Any date, in any month, that's less than 12 is getting the month
and date switched around
- For some reason using the MonthName() function returns month
names in Finnish instead of English. O.o Why on earth would I get
Finnish instead of English? I've checked the regional settings on
the server,

Again, probably you are wrong.
[please do not quote signatures]
>
Sorry but I don't see how I can be wrong about the month name coming
back in a different language?
I did not say that. I think you are wrong about the regional settings
used by your IIS. It must be one of the two, don't you think?

I showed you the solution by never depending on the IIS iregional
settings.
It really was coming back in a
different language. I even took a screenshot to show someone else
that didn't believe me. O.o
the PC I'm browsing/developing in, and the settings in the browsers
(Firefox 2 and IE7).

If this is about serverside asp-vbs code,
it has nothing to do with browser settings
BTW, I only mentioned the browser settings as I thought people might
question it. If you look back I mentioned the IIS configuration.
OK.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 4 '07 #10

P: n/a
Just wanted to follow-up on this in case others find the thread.

I still have no idea what the problem was but the behavior disappeared
after two reboots of the physical server. I'm suspecting a update
conflict.

And, for my sanity, I was NOT wrong about the regional settings on the
server. I checked them four times. It would make sense that this
would have been the problem but the settings were always correct when
I went in to look.

May 14 '07 #11

P: n/a
TofuTheGreat wrote on 14 mei 2007 in
microsoft.public.inetserver.asp.general:
Just wanted to follow-up on this in case others find the thread.
What areyou talking about?

[please always quote on usenet]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 14 '07 #12

P: n/a

"TofuTheGreat" <To**********@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
Just wanted to follow-up on this in case others find the thread.

I still have no idea what the problem was but the behavior disappeared
after two reboots of the physical server. I'm suspecting a update
conflict.

And, for my sanity, I was NOT wrong about the regional settings on the
server. I checked them four times. It would make sense that this
would have been the problem but the settings were always correct when
I went in to look.
Re-Read my NB in my previous response to your question. It is quite
possible that after some future restart the problem will re-appear.
May 17 '07 #13

This discussion thread is closed

Replies have been disabled for this discussion.