Date format

P

Paulo

Any function on ASP to format date on dd/mm/yyyy?
The format (VB) function does not work on ASP ?

Thanks!
 
P

Paulo

Any way to optimize it ?

<% sDia = ""
sMes = ""
sAno = ""
sData = ""
if not IsNull(rs("DT_EXAME")) then
sDia = Day(rs("DT_EXAME"))
sMes = Month(rs("DT_EXAME"))
sAno = Year(rs("DT_EXAME"))
if Len(sDia) = 1 then sDia = "0" & sDia
if Len(sMes) = 1 then sMes = "0" & sMes
sData = sDia & "/" & sMes & "/" & sAno
end if
%>

returns the dd/mm/yyyy coming from a db date field with left-zero filled
 
E

Evertjan.

McKirahan wrote on 15 feb 2008 in microsoft.public.inetserver.asp.general:
<%
Response.Write rs("DT_EXAME") & " = " & MDY(rs("DT_EXAME"))

Function MDY(DT)
MDY = ""
If IsDate(DT) Then
MDY = Right(100+Day(DT),2) & "/" _
& Right(100+Month(DT),2) & "/" & Year(DT)
End If
End Function
%>

<%

response.write dateToString(#2008-02-15#, "dd/mm/yyyy") & "<br>"
response.write dateToString(#2008-02-16#, "m/d/yyyy")

function dateToString(d, frmt)
aF = split(frmt,"/")
for i=0 to 2
if aF(i) = "d" then aF(i) = day(d)
if aF(i) = "dd" then aF(i) = right("0"&day(d),2)
if aF(i) = "m" then aF(i) = month(d)
if aF(i) = "mm" then aF(i) = right("0"&month(d),2)
if aF(i) = "yyyy" then aF(i) = year(d)
next
dateToString= join(aF,"/")
end function

%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top