ASP formatting date
asp-classic
Solution
You can make use of the following functions:
Year(Now) '' Year in 4 digits
Month(Now) '' Month without leading zero
Day(Now) '' Day of the month without leading zero
DateAdd("d", <numofdays>, Now) '' add a number of days to your date
Read more about these (and other date functions) functions here.
If you need to add a leading zero:
function addLeadingZero(value)
addLeadingZero = value
if value < 10 then
addLeadingZero = "0" & value
end if
end function
An example of your case would be:
Dim today, myDate
today = Now
for i = -6 to 0
myDate = DateAdd("d", i, today)
response.write "<a href=""20a.asp?cldate=" & Year(myDate) & addLeadingZero(Month(myDate)) & addLeadingZero(Day(myDate)) & """ target=""_blank"">X</a>"
next
Problem
Hello there I'm trying to get a date in ASP to show up in a particular format (yyyymmdd). This is what I've tried so far but no luck. Any help is appreciated. Thanks ``` <tr> <td><b>Call Date</b></td> <% for i = -6 to 0 %> <td align=center> <a href="20a.asp?cldate=<% response.write(DateTime.Date()+i.ToString("yyyyMMdd")) %>" target="_blank">X</a> </td> <% Next %> </tr> ```