Split, convert date question ??

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

    Split, convert date question ??

    Hi,

    I have a form which is posting a user entered date to an asp page.
    The date is then used in a SQL string.

    The format of the date is received as dd/mm/yyyy, with the user typing
    the '/' as well

    how can I convert it to yyyy-mm-dd

    ----------------

    I have tried this, but I think I need to strip out the '/' ??, as it is
    not working

    D1 = cdate(request.f orm("date"))

    strDay = Day(D1)
    strMonth = Month(D1)
    strYear = Year(D1)

    NewstrDate = strYear & "-" & strMonth & "-" & strDay

    Appreciate your help, thanks so much :-)

  • Mike Brind

    #2
    Re: Split, convert date question ??

    "David" <davidgordon@sc ene-double.co.ukwro te in message
    news:1159963404 .439496.242950@ e3g2000cwe.goog legroups.com...
    Hi,
    >
    I have a form which is posting a user entered date to an asp page.
    The date is then used in a SQL string.
    >
    The format of the date is received as dd/mm/yyyy, with the user typing
    the '/' as well
    >
    how can I convert it to yyyy-mm-dd
    >
    ----------------
    >
    I have tried this, but I think I need to strip out the '/' ??, as it is
    not working
    >
    D1 = cdate(request.f orm("date"))
    >
    strDay = Day(D1)
    strMonth = Month(D1)
    strYear = Year(D1)
    >
    NewstrDate = strYear & "-" & strMonth & "-" & strDay
    >
    Appreciate your help, thanks so much :-)
    >
    You almost had it - you need to use the Split() function:

    <%
    Function changeUserDate( userDate)
    temp = Split(userDate, "/")
    strDay = temp(0)
    strMonth = temp(1)
    strYear = temp(2)
    changeUserDate = strYear & "-" & strMonth & "-" & strDay
    End Function

    Response.Write changeUserDate( Request.Form("d ate"))
    %>

    Personally, I use a javascript calendar so that users can select dates for
    forms. That way I can manage the format of the input and don't have to do
    anything with it serverside, except check it's there (and check that end
    dates come after start dates etc...).

    There are a number of these knocking about on javascript code sites. Google
    will find one for you easily enough.

    --
    Mike Brind


    Comment

    • Evertjan.

      #3
      Re: Split, convert date question ??

      On 04 okt 2006, you wrote in microsoft.publi c.inetserver.as p.general:
      <%
      Function changeUserDate( userDate)
      temp = Split(userDate, "/")
      strDay = temp(0)
      strMonth = temp(1)
      strYear = temp(2)
      changeUserDate = strYear & "-" & strMonth & "-" & strDay
      End Function
      >
      Response.Write changeUserDate( Request.Form("d ate"))
      %>
      >
      <%
      Response.Write changeUserDate( Request.Form("d ate"))

      Function changeUserDate( userDate)
      dim result(3)
      temp = Split(userDate, "/")
      result(2) = temp(0)
      result(1) = temp(1)
      result(0) = temp(2)
      changeUserDate = Join(result,"-")
      End Function
      %>


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

      Comment

      • Mike Brind

        #4
        Re: Split, convert date question ??

        "Evertjan." <exjxw.hannivoo rt@interxnl.net wrote in message
        news:Xns9852A79 24210Eeejj99@19 4.109.133.242.. .
        On 04 okt 2006, you wrote in microsoft.publi c.inetserver.as p.general:
        >
        ><%
        >Function changeUserDate( userDate)
        >temp = Split(userDate, "/")
        >strDay = temp(0)
        >strMonth = temp(1)
        >strYear = temp(2)
        >changeUserDa te = strYear & "-" & strMonth & "-" & strDay
        >End Function
        >>
        >Response.Wri te changeUserDate( Request.Form("d ate"))
        >%>
        >>
        >
        <%
        Response.Write changeUserDate( Request.Form("d ate"))
        >
        Function changeUserDate( userDate)
        dim result(3)
        temp = Split(userDate, "/")
        result(2) = temp(0)
        result(1) = temp(1)
        result(0) = temp(2)
        changeUserDate = Join(result,"-")
        End Function
        %>
        Now that I like :-)

        --
        Mike Brind


        Comment

        Working...