Split, convert date question ??

Discussion in 'ASP General' started by David, Oct 4, 2006.

  1. David

    David Guest

    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.form("date"))

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

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

    Appreciate your help, thanks so much :)
    David, Oct 4, 2006
    #1
    1. Advertising

  2. David

    Mike Brind Guest

    "David" <> wrote in message
    news:...
    > 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.form("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("date"))
    %>

    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
    Mike Brind, Oct 4, 2006
    #2
    1. Advertising

  3. David

    Evertjan. Guest

    On 04 okt 2006, you wrote in microsoft.public.inetserver.asp.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("date"))
    > %>
    >


    <%
    Response.Write changeUserDate(Request.Form("date"))

    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)
    Evertjan., Oct 4, 2006
    #3
  4. David

    Mike Brind Guest

    "Evertjan." <> wrote in message
    news:Xns9852A7924210Eeejj99@194.109.133.242...
    > On 04 okt 2006, you wrote in microsoft.public.inetserver.asp.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("date"))
    >> %>
    >>

    >
    > <%
    > Response.Write changeUserDate(Request.Form("date"))
    >
    > 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
    Mike Brind, Oct 4, 2006
    #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. h_ghanaty

    convert gregorian date to jalay date

    h_ghanaty, Nov 7, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    518
    Bret Mulvey [MS]
    Nov 9, 2003
  2. =?Utf-8?B?UmFqYQ==?=

    Convert Julian Date to VB.NET date

    =?Utf-8?B?UmFqYQ==?=, Nov 12, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    5,982
    =?Utf-8?B?UGF1bA==?=
    Nov 12, 2004
  3. Sam
    Replies:
    1
    Views:
    5,116
    Pete Davis
    Apr 27, 2005
  4. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,229
    Michael Borgwardt
    May 30, 2004
  5. wgan
    Replies:
    7
    Views:
    580
    Roedy Green
    Jul 8, 2004
Loading...

Share This Page