<body> <% Function CountDown(Slut) s_s = DateDiff("s", Slut, Now) s_u = s_s Mod 604800 u = (s_s - s_u) / 604800 s_d = s_u Mod 86400 d = (s_u - s_d) / 86400 t = Round(s_d / 3600) CountDown = "Der er nu " & u & " uger og " & d & " dage tilbage til den "
& Slut & ".."
End Function
' Med angivelse af dato Response.Write CountDown("11-04-2005") %> <br>
her er en Simple og nem countdown function, som jeg lige bikset sammen for dig: <% Function WeekAndDaysToGo(TargetDate) Dim DaysToGo,WeekSToGo,OutPutString DaysToGo = datediff("d",now,TargetDate) WeekSToGo = Fix(DaysToGo / 7) DaysToGo = DaysToGo - cint(WeekSToGo * 7) if WeekSToGo > 0 then OutPutString = OutPutString & WeekSToGo & " Uge" if WeekSToGo > 1 then OutPutString = OutPutString & "r" if WeekSToGo > 0 then OutPutString = OutPutString & " og " if DaysToGo > 0 then OutPutString = OutPutString & DaysToGo & " Dag" if DaysToGo > 1 then OutPutString = OutPutString & "e" WeekAndDaysToGo = OutPutString end function %>
Brug den på følgende måde
<Body> <%= WeekAndDaysToGo("")%> </body>
Udskriften ville være (Hvis vi antager Now = idag 03-05-2005): 4 Uger og 1 Dag
UPS!!!!!!!! glemte lige TargetDate'en hehe Så det jeg mente var... Udskift ovenstående fra body tag til body end tag <Body> <%= WeekAndDaysToGo("1-06-2005")%> </body>
Hmmm... jeg har lige taget den kode du skrev om på min køre det bare... Kommer den ikke med fejl eller noget som helst????
NB: der er lige en rettelse... koden skal se sådan her ud: <% function WeekAndDaysToGo(TargetDate) Dim DaysToGo,WeekSToGo,OutPutString DaysToGo = datediff("d",now,Cdate(TargetDate)) WeekSToGo = Fix(DaysToGo / 7) DaysToGo = DaysToGo - cint(WeekSToGo * 7) if WeekSToGo > 0 then OutPutString = OutPutString & WeekSToGo & " Uge" if WeekSToGo > 1 then OutPutString = OutPutString & "r" if DaysToGo > 0 then OutPutString = OutPutString & " og " if DaysToGo > 0 then OutPutString = OutPutString & DaysToGo & " Dag" if DaysToGo > 1 then OutPutString = OutPutString & "e" WeekAndDaysToGo = OutPutString end function %>
- Før var denne linie: if WeekSToGo > 0 then OutPutString = OutPutString & " og "
- Er blevet ændret til: if DaysToGo > 0 then OutPutString = OutPutString & " og "
- Før var det WeekSToGo to bestemte om "Og" skulle med i virkeligheden skal det jo selvfølgelig være DaysToGo variablen.
Plus jeg også lige for en sikkerheds skyld bruger Dato konvertering funktionen på Targetdate, så den nu er Cdate(TargetDate)
Nå men for at teste det her kan vi jo gøre følgende: - Er det på din egen computer du tester den ??? - Hvilken server køre det på (OS version ???) - Prøv at udskrive de forskellige variabler sådan her: (herunder test versionen af funktioenen)
<% function WeekAndDaysToGo(TargetDate) Dim DaysToGo,WeekSToGo,OutPutString DaysToGo = datediff("d",now,TargetDate) response.write "DaysToGo = " & DaysToGo & "<br>"
if WeekSToGo > 0 then OutPutString = OutPutString & WeekSToGo & " Uge" if WeekSToGo > 1 then OutPutString = OutPutString & "r" if DaysToGo > 0 then OutPutString = OutPutString & " og " if DaysToGo > 0 then OutPutString = OutPutString & DaysToGo & " Dag" if DaysToGo > 1 then OutPutString = OutPutString & "e" WeekAndDaysToGo = OutPutString end function %>
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.