Another DateDiff() problem to add to the list
Another DateDiff() problem to add to the list
am 01.05.2007 17:40:39 von TofuTheGreat
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:
[code]
dim ArrivalDate, DepartureDate, NumNights
ArrivalDate = request.form("txtArrivalDate")
DepartureDate = request.form("txtDepartureDate")
NumNights = Datediff("d", cdate(ArrivalDate),cdate(DepartureDate))
[/code]
Major PITA going on here.
Re: Another DateDiff() problem to add to the list
am 01.05.2007 19:50:31 von exjxw.hannivoort
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:
>
> [code]
> dim ArrivalDate, DepartureDate, NumNights
>
> ArrivalDate = request.form("txtArrivalDate")
> DepartureDate = request.form("txtDepartureDate")
>
> NumNights = Datediff("d", cdate(ArrivalDate),cdate(DepartureDate))
> [/code]
Testing/debugging will give you the answer:
<%
d1 = "5/2/2007"
d2 = "5/19/2007"
response.write "month(d1): " & month(d1) & "
"
response.write "month(d2): " & month(d2) & "
"
r = Datediff("d", cdate(d1),cdate(d2))
response.write "difference in days: " & r & "
"
%>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Re: Another DateDiff() problem to add to the list
am 01.05.2007 19:55:23 von reb01501
TofuTheGreat@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:
>
> [code]
> dim ArrivalDate, DepartureDate, NumNights
>
> ArrivalDate = request.form("txtArrivalDate")
> DepartureDate = request.form("txtDepartureDate")
>
> NumNights = Datediff("d", cdate(ArrivalDate),cdate(DepartureDate))
> [/code]
>
> 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.
Re: Another DateDiff() problem to add to the list
am 02.05.2007 16:18:49 von TofuTheGreat
On May 1, 12:55 pm, "Bob Barrows [MVP]"
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).
Re: Another DateDiff() problem to add to the list
am 02.05.2007 17:43:19 von exjxw.hannivoort
TofuTheGreat wrote on 02 mei 2007 in
microsoft.public.inetserver.asp.general:
> On May 1, 12:55 pm, "Bob Barrows [MVP]"
> 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)
Re: Another DateDiff() problem to add to the list
am 02.05.2007 17:51:38 von reb01501
TofuTheGreat wrote:
> On May 1, 12:55 pm, "Bob Barrows [MVP]"
> 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.
Re: Another DateDiff() problem to add to the list
am 03.05.2007 09:52:54 von Anthony Jones
"TofuTheGreat" wrote in message
news:1178115529.135916.270820@y5g2000hsa.googlegroups.com...
> On May 1, 12:55 pm, "Bob Barrows [MVP]"
> 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).
>
Re: Another DateDiff() problem to add to the list
am 03.05.2007 10:34:38 von exjxw.hannivoort
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 & "
"
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Re: Another DateDiff() problem to add to the list
am 04.05.2007 17:36:59 von TofuTheGreat
On May 2, 10:43 am, "Evertjan." wrote:
> > 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.
Re: Another DateDiff() problem to add to the list
am 04.05.2007 17:56:41 von exjxw.hannivoort
TofuTheGreat wrote on 04 mei 2007 in
microsoft.public.inetserver.asp.general:
> On May 2, 10:43 am, "Evertjan." wrote:
>> > 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)
Re: Another DateDiff() problem to add to the list
am 14.05.2007 18:21:08 von TofuTheGreat
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: Another DateDiff() problem to add to the list
am 14.05.2007 21:20:51 von exjxw.hannivoort
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)
Re: Another DateDiff() problem to add to the list
am 17.05.2007 11:08:47 von Anthony Jones
"TofuTheGreat" wrote in message
news:1179159668.824407.137690@k79g2000hse.googlegroups.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.