Date Conv

Discussion in 'ASP General' started by A.Dagostino, Jan 11, 2006.

  1. A.Dagostino

    A.Dagostino Guest

    i have in my page an input text with a date like this "18/10/2005" i need to
    convert this value to lunch a select on SQL2000 like this "WHERE
    (dataAssunzione = CONVERT(DATETIME, '2005-10-18 00:00:00', 102))"

    How can i convert this date ?

    Thanks
     
    A.Dagostino, Jan 11, 2006
    #1
    1. Advertising

  2. A.Dagostino wrote:
    > i have in my page an input text with a date like this "18/10/2005" i
    > need to convert this value to lunch a select on SQL2000 like this
    > "WHERE (dataAssunzione = CONVERT(DATETIME, '2005-10-18 00:00:00',
    > 102))"
    > How can i convert this date ?
    >


    Do the Regional Settings on your server allow this text to be recognized as
    a date? I.E., does this statement raise an error?

    Response.Write CDate("18/10/2005")

    If this statement runs without error, see
    http://www.aspfaq.com/show.asp?id=2313

    Otherwise, you will need to use basic string functions (Left, Mid and Right)
    to extract the date elements and recombine them into a database-friendly
    date format.

    Bob Barrows

    PS. you are going to unnecessary trouble in your example sql statement. All
    that is required is:
    WHERE dataAssunzione = '20051018'
    No need for the parentheses and no need for the CONVERT function.

    Also, given the lack of a parameter in te above example, it looks like you
    are planning to use dynamic sql to create and run this query. if so, please
    read:
    http://mvp.unixwiz.net/techtips/sql-injection.html
    http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23

    The surest way to defeat sql injection is to use parameters, either by using
    a Command object to pass parameter values to a string containing parameter
    markers:
    http://groups-beta.google.com/group/microsoft.public.inetserver.asp.db/msg/72e36562fee7804e

    or by using my preferred method of using stored procedures:
    http://tinyurl.com/jyy0


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Jan 11, 2006
    #2
    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. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,301
    Michael Borgwardt
    May 30, 2004
  2. Jeff Epler
    Replies:
    2
    Views:
    285
    Avraham Makeler
    Apr 21, 2004
  3. Aj

    decimal to string conv

    Aj, Feb 27, 2009, in forum: Python
    Replies:
    2
    Views:
    464
  4. mike

    date conv

    mike, Jul 28, 2005, in forum: Javascript
    Replies:
    4
    Views:
    135
    Dr John Stockton
    Jul 29, 2005
Loading...

Share This Page