2014-04-17 61 views
1

好吧,所以我的代码工作正常,但我需要它添加一天到OrderDate,同时保持它在相同的格式yyyy-mm-dd任何帮助极大赞赏!我需要添加一天到我的日期在我的代码,试过DateAdd

<% 
inDate = oRS("ordDate") 

' get each date component 
thisMonth = datepart("M",inDate) 
thisDay = datepart("D",inDate) 
thisYear = datepart("yyyy",inDate) 

' check for the length of the month and day components 
if len(thisMonth) < 2 then thisMonth = "0" & thisMonth 
if len(thisDay) < 2 then thisDay = "0" & thisDay 

' Create the date in your format you posted above 
OrderDate = thisYear & "-" & thisMonth & "-" & thisDay 
%> 

回答

0

试试这个:

dim sOrderDate 
sOrderDate=cInt(thisDay)+1 

if len(thisDay) < 2 then thisDay = "0" & thisDay 
if len(sOrderDate) < 2 then sOrderDate = "0" & sOrderDate 

OrderDate = thisYear & "-" & thisMonth & "-" & sOrderDate 

这样您保留了操纵和订单日期原始日期(THISDAY)成为明日(或其他)的日期。

+2

我回来删除的问题,我可以只使用:\t \t THISDAY =日期部分(“d”,使用DateAdd(“d”,1,铟酸)) – BWalt302

+0

,将工作,但您可能希望保留记录的原始日期。特别是如果你处理金钱交易。 –

+0

此代码的目的只是为了生成预计发货日期,这是大多数情况下总是在订单后1天,有时是同一天。但是原始日期仍然可以在订单表中找到。谢谢您的帮助!我继续选择你的答案作为答案。 – BWalt302

1

以您的代码为例,只需使用DateAdd()即可将日期递增1个日历日;

<% 
inDate = oRS("ordDate") 
'Add one day 
inDate = DateAdd("d", 1, inDate) 

' get each date component 
thisMonth = datepart("M",inDate) 
thisDay = datepart("D",inDate) 
thisYear = datepart("yyyy",inDate) 

' check for the length of the month and day components 
if len(thisMonth) < 2 then thisMonth = "0" & thisMonth 
if len(thisDay) < 2 then thisDay = "0" & thisDay 

' Create the date in your format you posted above 
OrderDate = thisYear & "-" & thisMonth & "-" & thisDay 
%> 

对于日期见Classic ASP - Format current date and time工作的更多信息。

+0

你没看过他的评论吗?他已经做到了,并且效率更高! –

+0

@AllBlond他做到了,但这不仅仅是为了他的利益,你的答案提供了一种解决方法,需要额外验证生成的日期。这个解决方案更接近OP最终要求和做的。如果OP添加了我建议的答案,我会删除我的。 – Lankymart

+0

这是我的观点。你为什么给他发布他的答案?如果他喜欢,他可以做,并接受他的解决方案作为答案,而不是你。 –