Date format

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paulo

    Date format

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

    Thanks!


  • McKirahan

    #2
    Re: Date format

    "Paulo" <prbspfc@uol.co m.brwrote in message
    news:OmnBlm#bIH A.1960@TK2MSFTN GP02.phx.gbl...
    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


    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.


    Comment

    • Paulo

      #3
      Re: Date format

      Any way to optimize it ?

      <% sDia = ""
      sMes = ""
      sAno = ""
      sData = ""
      if not IsNull(rs("DT_E XAME")) then
      sDia = Day(rs("DT_EXAM E"))
      sMes = Month(rs("DT_EX AME"))
      sAno = Year(rs("DT_EXA ME"))
      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" <News@McKirahan .comescreveu na mensagem
      news:TKSdnZ9gsJ UZKyjanZ2dnUVZ_ tWtnZ2d@comcast .com...
      "Paulo" <prbspfc@uol.co m.brwrote in message
      news:OmnBlm#bIH A.1960@TK2MSFTN GP02.phx.gbl...
      >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

      >
      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.
      >
      >

      Comment

      • Jon Paal [MSMD]

        #4
        Re: Date format





        "Paulo" <prbspfc@uol.co m.brwrote in message news:ezaNh0%23b IHA.1208@TK2MSF TNGP05.phx.gbl. ..
        Any way to optimize it ?
        >
        <% sDia = ""
        sMes = ""
        sAno = ""
        sData = ""
        if not IsNull(rs("DT_E XAME")) then
        sDia = Day(rs("DT_EXAM E"))
        sMes = Month(rs("DT_EX AME"))
        sAno = Year(rs("DT_EXA ME"))
        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" <News@McKirahan .comescreveu na mensagem news:TKSdnZ9gsJ UZKyjanZ2dnUVZ_ tWtnZ2d@comcast .com...
        >"Paulo" <prbspfc@uol.co m.brwrote in message
        >news:OmnBlm#bI HA.1960@TK2MSFT NGP02.phx.gbl.. .
        >>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.
        >>
        >>
        >
        >

        Comment

        • McKirahan

          #5
          Re: Date format

          "Paulo" <prbspfc@uol.co m.brwrote in message
          news:ezaNh0#bIH A.1208@TK2MSFTN GP05.phx.gbl...
          Any way to optimize it ?
          >
          <% sDia = ""
          sMes = ""
          sAno = ""
          sData = ""
          if not IsNull(rs("DT_E XAME")) then
          sDia = Day(rs("DT_EXAM E"))
          sMes = Month(rs("DT_EX AME"))
          sAno = Year(rs("DT_EXA ME"))
          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
          [snip]

          Please don't top post as it makes the conversation harder to follow.

          Try this untested code:

          <%
          Response.Write rs("DT_EXAME") & " = " & MDY(rs("DT_EXAM E"))

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


          Comment

          • McKirahan

            #6
            Re: Date format

            "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot comwrote in message
            news:13rbf6s719 a64c5@corp.supe rnews.com...[snip]

            Interesting idea; however, the following

            <%
            Response.Write "<li>" & FormatDateTime( Now,2)
            Session.lcid=20 57 '= UK English
            Response.Write "<li>" & FormatDateTime( Now,2)
            Session.lcid=10 33 '= US English
            Response.Write "<li>" & FormatDateTime( Now,2)
            %>

            returned (for me):

            2/15/2008
            15/02/08
            2/15/2008


            Comment

            • Bob Barrows [MVP]

              #7
              Re: Date format

              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.


              Comment

              • Jon Paal [MSMD]

                #8
                Re: Date format

                W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.






                "McKirahan" <News@McKirahan .comwrote in message news:odKdnU_-1uNTXyjanZ2dnUV Z_gmdnZ2d@comca st.com...
                "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot comwrote in message
                news:13rbf6s719 a64c5@corp.supe rnews.com...>
                [snip]
                >
                Interesting idea; however, the following
                >
                <%
                Response.Write "<li>" & FormatDateTime( Now,2)
                Session.lcid=20 57 '= UK English
                Response.Write "<li>" & FormatDateTime( Now,2)
                Session.lcid=10 33 '= US English
                Response.Write "<li>" & FormatDateTime( Now,2)
                %>
                >
                returned (for me):
                >
                2/15/2008
                15/02/08
                2/15/2008
                >
                >

                Comment

                • Evertjan.

                  #9
                  Re: Date format

                  McKirahan wrote on 15 feb 2008 in microsoft.publi c.inetserver.as p.general:
                  <%
                  Response.Write rs("DT_EXAME") & " = " & MDY(rs("DT_EXAM E"))
                  >
                  Function MDY(DT)
                  MDY = ""
                  If IsDate(DT) Then
                  MDY = Right(100+Day(D T),2) & "/" _
                  & Right(100+Month (DT),2) & "/" & Year(DT)
                  End If
                  End Function
                  %>
                  >
                  <%

                  response.write dateToString(#2 008-02-15#, "dd/mm/yyyy") & "<br>"
                  response.write dateToString(#2 008-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)

                  Comment

                  • Jon Paal [MSMD]

                    #10
                    Re: Date format

                    also see this:

                    eSports News, Results, upcoming Matches & live Matches. Learn tricks and guides in the esports space. ✅ We cover CS:GO, Dota 2, LOL, Overwatch & PUBG. 




                    "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot comwrote in message news:13rbiku4vh 38g58@corp.supe rnews.com...
                    W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

                    >
                    >
                    >
                    >
                    >
                    "McKirahan" <News@McKirahan .comwrote in message news:odKdnU_-1uNTXyjanZ2dnUV Z_gmdnZ2d@comca st.com...
                    >"Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot comwrote in message
                    >news:13rbf6s71 9a64c5@corp.sup ernews.com...>>
                    >[snip]
                    >>
                    >Interesting idea; however, the following
                    >>
                    ><%
                    >Response.Wri te "<li>" & FormatDateTime( Now,2)
                    >Session.lcid=2 057 '= UK English
                    >Response.Wri te "<li>" & FormatDateTime( Now,2)
                    >Session.lcid=1 033 '= US English
                    >Response.Wri te "<li>" & FormatDateTime( Now,2)
                    >%>
                    >>
                    >returned (for me):
                    >>
                    >2/15/2008
                    >15/02/08
                    >2/15/2008
                    >>
                    >>
                    >
                    >

                    Comment

                    Working...