Date format

Discussion in 'ASP General' started by Paulo, Feb 15, 2008.

  1. Paulo

    Paulo Guest

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

    Thanks!
    Paulo, Feb 15, 2008
    #1
    1. Advertising

  2. Paulo

    Paulo Guest

    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" <> escreveu na mensagem
    news:...
    > "Paulo" <> wrote in message
    > news:OmnBlm#...
    >> 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/func_formatdatetime.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.
    >
    >
    Paulo, Feb 15, 2008
    #2
    1. Advertising

  3. 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.
    Bob Barrows [MVP], Feb 15, 2008
    #3
  4. Paulo

    Evertjan. Guest

    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)
    Evertjan., Feb 15, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candy
    Replies:
    2
    Views:
    1,135
    Janaka
    Feb 18, 2004
  2. DC
    Replies:
    5
    Views:
    2,987
    Brendan Reynolds
    Jul 1, 2005
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,193
    Michael Borgwardt
    May 30, 2004
  4. Chu
    Replies:
    3
    Views:
    4,163
    Shawn
    Aug 15, 2006
  5. Josh Sharpe
    Replies:
    1
    Views:
    194
    Brian Candler
    Sep 21, 2010
Loading...

Share This Page