Domanda

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
%>
È stato utile?

Soluzione 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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top