<code> Kolla lite på funktionen DateDiff(http://msdn.microsoft.com/library/en-us/vbenlr98/html/vafctDateDiff.asp) Detta kanske är till någon hjälp:korta ner koden
<%
if DatePart("h",Now) - DatePart("h",senastinloggad) = 1 then
tim="timme"
else
tim="timmar"
end if
if DatePart("n",Now) - DatePart("n",senastinloggad) = 1 then
min="minut"
else
min="minuter"
end if
if DatePart("s",Now) - DatePart("s",senastinloggad) = 1 then
sek="sekund"
else
sek="sekunder"
end if
If DatePart("n",senastinloggad) = Datepart("n",now) and DatePart("h",senastinloggad) = Datepart("h",now) and DatePart("d",senastinloggad) = Datepart("d",now) and DatePart("m",senastinloggad) = Datepart("m",now) and DatePart("yyyy",senastinloggad) = Datepart("yyyy",now) then
response.write(DatePart("s",Now) - DatePart("s",senastinloggad) & " " & sek &" sedan.")
elseIf DatePart("h",senastinloggad) = Datepart("h",now) and DatePart("d",senastinloggad) = Datepart("d",now) and DatePart("m",senastinloggad) = Datepart("m",now) and DatePart("yyyy",senastinloggad) = Datepart("yyyy",now) Then
response.write(DatePart("n",Now) - DatePart("n",senastinloggad) & " " & min &" sedan.")
elseIf DatePart("d",senastinloggad) = Datepart("d",now) and DatePart("m",senastinloggad) = Datepart("m",now) and DatePart("yyyy",senastinloggad) = Datepart("yyyy",now) then
response.write(DatePart("h",Now) - DatePart("h",senastinloggad) & " " & tim &" sedan.")
else
response.write(now)
end if
%>
</code>
kan jag korta mer den loden på något smart sätt?Sv: korta ner koden
Sv: korta ner koden
<code>
Function FormatPart(Value, EttEnhet, Enhet)
If Value = 1 Then
FormatPart = Value & EttEnhet
ElseIf Value > 1 Then
FormatPart = Value & Enhet
End If
End Function
Function FormatTimeOnline(Value)
Dim TempDate
TempDate = Now() - Value
If TempDate > 1 Then
FormatTimeOnline = Value
Else
FormatTimeOnline = FormatPart(DatePart("h", TempDate), " timme ", " timmar ")
FormatTimeOnline = FormatTimeOnline & FormatPart(DatePart("n", TempDate), " minut ", " minuter ")
FormatTimeOnline = FormatTimeOnline & FormatPart(DatePart("s", TempDate), " sekund ", " sekunder ")
End If
End Function
Response.Write FormatTimeOnline(SenastInLoggad)
</code>