how to insert datetime into database using ASP?

Discussion in 'ASP General' started by Bon, Jul 28, 2006.

  1. Bon

    Bon Guest

    Dear all

    How can I convert a datetime in Short Date format to General Date
    format and then insert into SQL database?

    I get a date from a field using Request("in_date"), which is in Short
    Date format. Afterwards, I need to convert it into General Date and
    then insert the date into database. But, the date is always inserted as
    1/1/1900. Please give me some suggestions.

    Cheers
    Bon
     
    Bon, Jul 28, 2006
    #1
    1. Advertising

  2. Bon

    Bobbo Guest

    Bon wrote:

    > How can I convert a datetime in Short Date format to General Date
    > format and then insert into SQL database?


    You're best off avoiding tampering with date formats wherever possible
    - try to just store the date early on and format it when it's being
    read back out of the database. This way helps to avoid regional
    descrepancies and such.


    > the date is always inserted as
    > 1/1/1900. Please give me some suggestions.


    This could be happening for one of several reasons:

    1. You're working on some kind of history database and the original
    date entered was the 1st Jan 1900. I'm guessing this is the least
    likely option.
    2. Your format conversion code has a bug. See my comment earlier.
    3. The date isn't being passed to the table correctly and it has a
    default value set, which is being picked up.
    4. Something else bad is happening.
     
    Bobbo, Jul 28, 2006
    #2
    1. Advertising

  3. Bon wrote:
    > Dear all
    >
    > How can I convert a datetime in Short Date format to General Date
    > format and then insert into SQL database?
    >
    > I get a date from a field using Request("in_date"), which is in Short
    > Date format. Afterwards, I need to convert it into General Date and
    > then insert the date into database. But, the date is always inserted
    > as 1/1/1900. Please give me some suggestions.
    >

    http://www.aspfaq.com/show.asp?id=2040
    --
    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], Jul 28, 2006
    #3
  4. "Bon" <> wrote in message
    news:...
    > Dear all
    >
    > How can I convert a datetime in Short Date format to General Date
    > format and then insert into SQL database?
    >
    > I get a date from a field using Request("in_date"), which is in Short
    > Date format. Afterwards, I need to convert it into General Date and
    > then insert the date into database. But, the date is always inserted as
    > 1/1/1900. Please give me some suggestions.


    I would not convert it yourselves. A difference in the country setting of
    SQL and your current thread on ASP could cause difficulties already.

    Set cmd = CreateObject("ADODB.Command")
    'samples, assume field2 and field1 dates

    set cmd.activeconnection = myconn

    cmd.commandtext = "INSERT INTO myTable(field1, field2) VALUES(?,?)"
    cmd.commandtype =1
    cmd.parameters.append cmd.createparameter(, 135,,,CDate(mydate))
    cmd.parameters.append cmd.createparameter(, 135,,,#1-1-2025#)
    cmd.execute ,, 128
     
    Egbert Nierop \(MVP for IIS\), Jul 28, 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. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    719
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    544
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    397
    John Machin
    Jul 28, 2006
  4. Steve Kershaw
    Replies:
    5
    Views:
    5,928
    Steve Kershaw
    Aug 29, 2006
  5. Martin
    Replies:
    0
    Views:
    343
    Martin
    Dec 27, 2008
Loading...

Share This Page