Problems inserting a date field into Access db

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Problems inserting a date field into Access db

    Hi everybody:

    When I try to insert a Date field using the Date() function into a field
    that has a date type in an Access DB I obtain a time value of 12:01:18 AM
    instead of the value of the date that I see when I display the result of
    the Date() call using response.write.

    Any help would greatly be appreciated.

    Thanks

    Terry


    Terry Murray Guest

  2. Similar Questions and Discussions

    1. Inserting to empty date field
      Hello All, I have a form where updating a field with a null value works...(thanks to the forum)... but inserting doesn't seem to work with same...
    2. date/time field from access 2000 db getting -1 in textbox on form
      I am stuck in using Access 2000 with on Windows 2000 server. I get a negitive 1 for a value. My code $DB_Conn = new...
    3. Having problems with a date field
      Happy New Year Everybody! I am having problems when trying query an access database that has a couple of date/time fields. If I construct my...
    4. Linking date field to text field entry
      Is there a way to setup a date field that will automatically enter the date when any information is entered into a field next to it?
    5. Date problems with SQL (previously Access code)
      I have the following code: biddate = request("close_month") & "/" & request("close_day") & "/" & request("close_year") bidtime =...
  3. #2

    Default Re: Problems inserting a date field into Access db

    You don't have the correct delimiters. You are, instead, submitting
    something like 6/9/2003, which is 6 divided by 9 divided by 2003, which is a
    small number, which equates to 1 minute and 18 seconds past midnight on
    1/1/1900.

    Instead, do:

    strSQL = _
    "INSERT INTO myTable (myDateField) VALUES (#" & Date() & "#)"

    The # tell Access that you are submitting a string that's supposed to be
    interpreted as a date.

    However, if you just want to insert the current date, Access, internally,
    has a Date() function as well, which you can call like this:

    strSQL = _
    "INSERT INTO myTable (myDateField) VALUES (Date())"

    Cheers
    Ken

    "Terry Murray" <tgmurray@rogers.com> wrote in message
    news:mqb6b.393104$4UE.81627@news01.bloor.is.net.ca ble.rogers.com...
    : Hi everybody:
    :
    : When I try to insert a Date field using the Date() function into a
    field
    : that has a date type in an Access DB I obtain a time value of 12:01:18 AM
    : instead of the value of the date that I see when I display the result of
    : the Date() call using response.write.
    :
    : Any help would greatly be appreciated.
    :
    : Thanks
    :
    : Terry
    :
    :


    Ken Schaefer Guest

  4. #3

    Default Re: Problems inserting a date field into Access db

    Thanks for the very quick response Ken. I did try using the Date function
    directly the way you show it and received the same result.
    Thanks again
    Terry
    "Ken Schaefer" <kenREMOVE@THISadOpenStatic.com> wrote in message
    news:utiDw7BdDHA.1656@TK2MSFTNGP10.phx.gbl...
    > You don't have the correct delimiters. You are, instead, submitting
    > something like 6/9/2003, which is 6 divided by 9 divided by 2003, which is
    a
    > small number, which equates to 1 minute and 18 seconds past midnight on
    > 1/1/1900.
    >
    > Instead, do:
    >
    > strSQL = _
    > "INSERT INTO myTable (myDateField) VALUES (#" & Date() & "#)"
    >
    > The # tell Access that you are submitting a string that's supposed to be
    > interpreted as a date.
    >
    > However, if you just want to insert the current date, Access, internally,
    > has a Date() function as well, which you can call like this:
    >
    > strSQL = _
    > "INSERT INTO myTable (myDateField) VALUES (Date())"
    >
    > Cheers
    > Ken
    >
    > "Terry Murray" <tgmurray@rogers.com> wrote in message
    > news:mqb6b.393104$4UE.81627@news01.bloor.is.net.ca ble.rogers.com...
    > : Hi everybody:
    > :
    > : When I try to insert a Date field using the Date() function into a
    > field
    > : that has a date type in an Access DB I obtain a time value of 12:01:18
    AM
    > : instead of the value of the date that I see when I display the result
    of
    > : the Date() call using response.write.
    > :
    > : Any help would greatly be appreciated.
    > :
    > : Thanks
    > :
    > : Terry
    > :
    > :
    >
    >

    Terry Murray Guest

  5. #4

    Default Re: Problems inserting a date field into Access db

    Which way did you try? I showed two different ways.

    Also, what type of field is your date/time field?

    Lastly, please post the code that you're actually using.

    Cheers
    Ken

    "Terry Murray" <tgmurray@rogers.com> wrote in message
    news:JNb6b.393224$4UE.110081@news01.bloor.is.net.c able.rogers.com...
    : Thanks for the very quick response Ken. I did try using the Date function
    : directly the way you show it and received the same result.
    : Thanks again
    : Terry
    : "Ken Schaefer" <kenREMOVE@THISadOpenStatic.com> wrote in message
    : news:utiDw7BdDHA.1656@TK2MSFTNGP10.phx.gbl...
    : > You don't have the correct delimiters. You are, instead, submitting
    : > something like 6/9/2003, which is 6 divided by 9 divided by 2003, which
    is
    : a
    : > small number, which equates to 1 minute and 18 seconds past midnight on
    : > 1/1/1900.
    : >
    : > Instead, do:
    : >
    : > strSQL = _
    : > "INSERT INTO myTable (myDateField) VALUES (#" & Date() & "#)"
    : >
    : > The # tell Access that you are submitting a string that's supposed to be
    : > interpreted as a date.
    : >
    : > However, if you just want to insert the current date, Access,
    internally,
    : > has a Date() function as well, which you can call like this:
    : >
    : > strSQL = _
    : > "INSERT INTO myTable (myDateField) VALUES (Date())"
    : >
    : > Cheers
    : > Ken
    : >
    : > "Terry Murray" <tgmurray@rogers.com> wrote in message
    : > news:mqb6b.393104$4UE.81627@news01.bloor.is.net.ca ble.rogers.com...
    : > : Hi everybody:
    : > :
    : > : When I try to insert a Date field using the Date() function into a
    : > field
    : > : that has a date type in an Access DB I obtain a time value of
    12:01:18
    : AM
    : > : instead of the value of the date that I see when I display the result
    : of
    : > : the Date() call using response.write.
    : > :
    : > : Any help would greatly be appreciated.
    : > :
    : > : Thanks
    : > :
    : > : Terry
    : > :
    : > :
    : >
    : >
    :
    :


    Ken Schaefer Guest

  6. #5

    Default Re: Problems inserting a date field into Access db

    Hi Ken, the sql statement that I constructed follows:

    sql = "INSERT INTO customers" & _
    "(firstname,lastname,address," & _
    "address_2,city,state,country," & _
    "postcode,email,BDATE," & _
    "password,userid,PW_QUE," & _
    "pw_answer, MANUAL_REG,PLAYER_ID," & _
    "phone,maillist,GENDER, logincount, lastlogindate) " & _
    "VALUES " & _
    "(" & "'" & fname & "','" & lname & "','" & straddress1 & "','" & _
    straddress2 & "','" & city & "','" & provstate & "','" & country &
    "','" & _
    poszip & "','" & email & "','" & bdate & "','" & _
    password & "','" & username & "'," & pw_que & ",'" & _
    pw_answer & "'," & "No" & ",'" & handle & "','" & _
    phonenum & "'," & maillist & ",'" & gender & "',1," & Date() &
    ")"

    lastlogindate is a Date/Time field in Access.

    Thanks
    Terry


    "Ken Schaefer" <kenREMOVE@THISadOpenStatic.com> wrote in message
    news:OvlG1bDdDHA.1884@TK2MSFTNGP10.phx.gbl...
    > Which way did you try? I showed two different ways.
    >
    > Also, what type of field is your date/time field?
    >
    > Lastly, please post the code that you're actually using.
    >
    > Cheers
    > Ken
    >
    > "Terry Murray" <tgmurray@rogers.com> wrote in message
    > news:JNb6b.393224$4UE.110081@news01.bloor.is.net.c able.rogers.com...
    > : Thanks for the very quick response Ken. I did try using the Date
    function
    > : directly the way you show it and received the same result.
    > : Thanks again
    > : Terry
    > : "Ken Schaefer" <kenREMOVE@THISadOpenStatic.com> wrote in message
    > : news:utiDw7BdDHA.1656@TK2MSFTNGP10.phx.gbl...
    > : > You don't have the correct delimiters. You are, instead, submitting
    > : > something like 6/9/2003, which is 6 divided by 9 divided by 2003,
    which
    > is
    > : a
    > : > small number, which equates to 1 minute and 18 seconds past midnight
    on
    > : > 1/1/1900.
    > : >
    > : > Instead, do:
    > : >
    > : > strSQL = _
    > : > "INSERT INTO myTable (myDateField) VALUES (#" & Date() & "#)"
    > : >
    > : > The # tell Access that you are submitting a string that's supposed to
    be
    > : > interpreted as a date.
    > : >
    > : > However, if you just want to insert the current date, Access,
    > internally,
    > : > has a Date() function as well, which you can call like this:
    > : >
    > : > strSQL = _
    > : > "INSERT INTO myTable (myDateField) VALUES (Date())"
    > : >
    > : > Cheers
    > : > Ken
    > : >
    > : > "Terry Murray" <tgmurray@rogers.com> wrote in message
    > : > news:mqb6b.393104$4UE.81627@news01.bloor.is.net.ca ble.rogers.com...
    > : > : Hi everybody:
    > : > :
    > : > : When I try to insert a Date field using the Date() function into
    a
    > : > field
    > : > : that has a date type in an Access DB I obtain a time value of
    > 12:01:18
    > : AM
    > : > : instead of the value of the date that I see when I display the
    result
    > : of
    > : > : the Date() call using response.write.
    > : > :
    > : > : Any help would greatly be appreciated.
    > : > :
    > : > : Thanks
    > : > :
    > : > : Terry
    > : > :
    > : > :
    > : >
    > : >
    > :
    > :
    >
    >

    Terry Murray Guest

  7. #6

    Default Re: Problems inserting a date field into Access db

    Hi Terry,

    That code below implements neither of my two suggestions. If you want to use
    the VBScript Date() function in your ASP code, then you need to also use the
    appropriate date/time delimeters (which are: #).

    strSQL = _
    "INSERT INTO myTable " & _
    "(myDateField) " & _
    "VALUES(#" & Date() & "#)"

    -or you can use the Date() function inside Access:

    strSQL = _
    "INSERT INTO myTable " & _
    "(myDateField) " & _
    "VALUES(Date())"

    Cheers
    Ken

    "Terry Murray" <tgmurray@rogers.com> wrote in message
    news:9zi6b.172152$_V.130846@news04.bloor.is.net.ca ble.rogers.com...
    : Hi Ken, the sql statement that I constructed follows:
    :
    : sql = "INSERT INTO customers" & _
    : "(firstname,lastname,address," & _
    : "address_2,city,state,country," & _
    : "postcode,email,BDATE," & _
    : "password,userid,PW_QUE," & _
    : "pw_answer, MANUAL_REG,PLAYER_ID," & _
    : "phone,maillist,GENDER, logincount, lastlogindate) " & _
    : "VALUES " & _
    : "(" & "'" & fname & "','" & lname & "','" & straddress1 & "','" & _
    : straddress2 & "','" & city & "','" & provstate & "','" & country &
    : "','" & _
    : poszip & "','" & email & "','" & bdate & "','" & _
    : password & "','" & username & "'," & pw_que & ",'" & _
    : pw_answer & "'," & "No" & ",'" & handle & "','" & _
    : phonenum & "'," & maillist & ",'" & gender & "',1," & Date() &
    : ")"
    :
    : lastlogindate is a Date/Time field in Access.
    :
    : Thanks
    : Terry
    :
    :
    : "Ken Schaefer" <kenREMOVE@THISadOpenStatic.com> wrote in message
    : news:OvlG1bDdDHA.1884@TK2MSFTNGP10.phx.gbl...
    : > Which way did you try? I showed two different ways.
    : >
    : > Also, what type of field is your date/time field?
    : >
    : > Lastly, please post the code that you're actually using.
    : >
    : > Cheers
    : > Ken
    : >
    : > "Terry Murray" <tgmurray@rogers.com> wrote in message
    : > news:JNb6b.393224$4UE.110081@news01.bloor.is.net.c able.rogers.com...
    : > : Thanks for the very quick response Ken. I did try using the Date
    : function
    : > : directly the way you show it and received the same result.
    : > : Thanks again
    : > : Terry
    : > : "Ken Schaefer" <kenREMOVE@THISadOpenStatic.com> wrote in message
    : > : news:utiDw7BdDHA.1656@TK2MSFTNGP10.phx.gbl...
    : > : > You don't have the correct delimiters. You are, instead, submitting
    : > : > something like 6/9/2003, which is 6 divided by 9 divided by 2003,
    : which
    : > is
    : > : a
    : > : > small number, which equates to 1 minute and 18 seconds past midnight
    : on
    : > : > 1/1/1900.
    : > : >
    : > : > Instead, do:
    : > : >
    : > : > strSQL = _
    : > : > "INSERT INTO myTable (myDateField) VALUES (#" & Date() & "#)"
    : > : >
    : > : > The # tell Access that you are submitting a string that's supposed
    to
    : be
    : > : > interpreted as a date.
    : > : >
    : > : > However, if you just want to insert the current date, Access,
    : > internally,
    : > : > has a Date() function as well, which you can call like this:
    : > : >
    : > : > strSQL = _
    : > : > "INSERT INTO myTable (myDateField) VALUES (Date())"
    : > : >
    : > : > Cheers
    : > : > Ken
    : > : >
    : > : > "Terry Murray" <tgmurray@rogers.com> wrote in message
    : > : > news:mqb6b.393104$4UE.81627@news01.bloor.is.net.ca ble.rogers.com...
    : > : > : Hi everybody:
    : > : > :
    : > : > : When I try to insert a Date field using the Date() function
    into
    : a
    : > : > field
    : > : > : that has a date type in an Access DB I obtain a time value of
    : > 12:01:18
    : > : AM
    : > : > : instead of the value of the date that I see when I display the
    : result
    : > : of
    : > : > : the Date() call using response.write.
    : > : > :
    : > : > : Any help would greatly be appreciated.
    : > : > :
    : > : > : Thanks
    : > : > :
    : > : > : Terry
    : > : > :
    : > : > :
    : > : >
    : > : >
    : > :
    : > :
    : >
    : >
    :
    :


    Ken Schaefer Guest

  8. #7

    Default Re: Problems inserting a date field into Access db

    Although certainly all of the responses from the guru's here are correct, if
    your goal is simply to insert the current date into the database at the time
    you create the record (in other words, when was this record created?), then
    the easiest way is to set the field in Access with a default date. Open the
    table in Access in design mode, go to the field in question, then in the
    default value section, put in Date()

    This will insert the current date automatically when the record is created,
    then you don't have to do it in ASP.


    "Terry Murray" <tgmurray@rogers.com> wrote in message
    news:mqb6b.393104$4UE.81627@news01.bloor.is.net.ca ble.rogers.com...
    > Hi everybody:
    >
    > When I try to insert a Date field using the Date() function into a
    field
    > that has a date type in an Access DB I obtain a time value of 12:01:18 AM
    > instead of the value of the date that I see when I display the result of
    > the Date() call using response.write.
    >
    > Any help would greatly be appreciated.
    >
    > Thanks
    >
    > Terry
    >
    >

    Terry Liston Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139