문제

Ok so my code works fine, however I need it to add one day to the OrderDate , while keeping it in the same format yyyy-mm-dd any help is greatly appreciated!

<%
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
%>
도움이 되었습니까?

해결책 2

try this:

 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

this way you preserve original date(thisDay) for manipulation and order date became tomorrow (or whatever) date.

다른 팁

Using your code as an example just use DateAdd() to increment the day by 1 calendar day;

<%
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
%>

For more information of working with dates see Classic ASP - Format current date and time.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top