简体   繁体   English

经典ASP,IIS6和IIS8之间的DATE区别

[英]Classic ASP, DATE difference between IIS6 and IIS8

I am helping to migrate a classic asp website (front end) and ms access database (back end) from a Windows 2003 IIS6 server to a Windows 2012 IIS 8.5 server. 我正在帮助将经典的ASP网站(前端)和ms Access数据库(后端)从Windows 2003 IIS6服务器迁移到Windows 2012 IIS 8.5服务器。 I am having a problem with this query in particular; 我对此查询特别有疑问;

sqlquery1 = "Select RentalNum, CarID, RentalStatus, StartDate, EndDate from table where CDate(EndDate) <= CDate('"&Date()&"') order by CDate(EndDate) desc"

On the existing system all is ok. 在现有系统上,一切正常。 On the new system the returned results are not <= "todays date". 在新系统上,返回的结果不是<=“ todays date”。 The results show some dates before today and some after. 结果显示了今天之前和之后的一些日期。 The database date fields are just "text" (I didn't set it up) and whilst my initial thoughts were to change the schema to proper dates, I would like to understand the problem, particularly as there are many of parts of the system using similar queries using date() and CDate. 数据库日期字段只是“文本”(我没有设置),虽然我最初的想法是将模式更改为正确的日期,但我还是想了解问题,特别是因为系统的许多部分使用类似的查询使用date()和CDate。 Are there underlying dates differences between IIS servers? IIS服务器之间是否存在基础日期差异? I have looked at browser locality and all is ok there. 我已经查看了浏览器的位置,并且一切正常。

Any pointers? 有指针吗?

Examine this expression used in your query: 检查查询中使用的以下表达式:

CDate('"&Date()&"')

The Date() function returns the system date as a Date/Time value. Date()函数返回系统日期作为日期/时间值。 But then that expression adds quotes before and after the Date/Time value, which transforms it to a string value. 但是随后,该表达式在“日期/时间”值之前和之后添加了引号,从而将其转换为字符串值。 And then CDate() takes that string and transforms it back to a Date/Time value again. 然后CDate()接收该字符串并将其再次转换回Date / Time值。

Hopefully that description convinces you those manipulations are at best wasted effort. 希望描述能使您确信这些操作充其量是浪费的。 However if the two servers have different date format settings, the dates resulting from that full CDate() expression could be different. 但是,如果两台服务器具有不同的日期格式设置,则该完整CDate()表达式产生的日期可能会不同。

I'm not positive that is the source of your problem, but you can easily eliminate the possibility. 我不认为这是问题的根源,但您可以轻松消除这种可能性。 The Access db engine supports the Date() function, so you can use it directly without first transforming it to a string and then back into a Date/Time value. Access db引擎支持Date()函数,因此您可以直接使用它,而无需先将其转换为字符串,然后再转换回Date / Time值。

sqlquery1 = "Select RentalNum, CarID, RentalStatus, StartDate, EndDate " & _
    "from [table] where CDate(EndDate) <= Date() order by CDate(EndDate) desc"

If that change does not solve the problem, next examine those EndDate text values and make sure they're interpreted as the date you expect: 如果该更改不能解决问题,请接下来检查那些EndDate文本值,并确保将其解释为您期望的日期:

SELECT EndDate, CDate(EndDate) AS EndDate_as_date
FROM [table];

You mentioned your "initial thoughts were to change the schema to proper dates" . 您提到了“最初的想法是将架构更改为正确的日期” I think that is the best way to go because developement based on dates as Date/Time is saner than with dates as strings. 我认为这是最好的方法,因为基于日期作为日期/时间进行开发比使用日期作为字符串更明智。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM