Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Date format

Reply
Thread Tools

Date format

 
 
Paulo
Guest
Posts: n/a
 
      02-15-2008
Any function on ASP to format date on dd/mm/yyyy?
The format (VB) function does not work on ASP ?

Thanks!


 
Reply With Quote
 
 
 
 
Paulo
Guest
Posts: n/a
 
      02-15-2008
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

"McKirahan" <(E-Mail Removed)> escreveu na mensagem
news:(E-Mail Removed). ..
> "Paulo" <(E-Mail Removed)> wrote in message
> news:OmnBlm#(E-Mail Removed)...
>> Any function on ASP to format date on dd/mm/yyyy?
>> The format (VB) function does not work on ASP ?

>
> FormatDateTime() may meet your needs.
>
> VBScript FormatDateTime Function
> http://www.w3schools.com/vbscript/fu...atdatetime.asp
>
> FormatDateTime(Now,2) = 02/15/2008 (mm/dd/yyyy) for me.
>
> If you need dd/mm/yyyy then you may have to construct it
> using DatePart(); for example, (where "x" is your date):
>
> DatePart("d",x) & "/" & DatePart("m",x) & "/" & DatePart("yyyy",x)
>
> Be aware that the day and month returned are not left-zero filled;
> that is, today's date will appear as 15/2/2008 unless adjusted.
>
>



 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      02-15-2008
Paulo wrote:
> Any function on ASP to format date on dd/mm/yyyy?
> The format (VB) function does not work on ASP ?
>

http://www.aspfaq.com/show.asp?id=2313 vbscript
http://www.aspfaq.com/show.asp?id=2040 help with dates


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      02-15-2008
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

%>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Date Format - best way of converting a string into a date format Brian Candy ASP .Net 2 02-18-2004 02:13 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Given a date, how to find the beginning date and ending date of that week Matt C Programming 3 11-08-2003 09:07 PM
Given a date, how to find the beginning date and ending date of that week Matt C++ 2 11-08-2003 08:30 PM



Advertisments