2013-01-15 67 views
0

這個月是我的代碼:墊「0」

If FinalMonth = "" OR FinalYear = "" Then 
    FinalMonth = Month(Now()) 
    FinalYear = Year(Now()) 
End If 

Select Case(FinalMonth) 
    Case "01","03","05","07","08","10","12" 
     FinalDay = "31" 
    Case "04","06","09","11" 
     FinalDay = "30" 
    Case "02" 
     If ((FinalYear Mod 4) <> 0) Then 
      FinalDay = "28" 
     Else 
      FinalDay = "29" 
     End If 
End Select 

我想我一個月被設定爲0 1號(1月)每個例子中,最後01個月之前,我該怎麼辦呢請?

回答

0

你可以;

If FinalMonth = "" OR FinalYear = "" Then 
    FinalMonth = Month(Now()) 
    FinalYear = Year(Now()) 
End If 

'get last day of month - add 1 month then deduct 1 day 
FinalDay = Day(DateSerial(FinalYear, FinalMonth + 1, 1) - 1) 

'pad month 
if (FinalMonth < 10) then FinalMonth = "0" & FinalMonth 
0

這是怎麼回事?

<%=Right("0" & Day(now()), 2)%>-<%=Right("0" & Month(now()), 2)%>-<%=Year(now())%> 

輸出:2018年10月2日