Insert a value of type Date/Time into a database

I am trying to insert a value of type date time into an access database. What is the format needed to insert the date/time.
Thanks,
-Amos

I had all kinds of problems getting a datetime inserted into a SQl Server DB. Probably similar so this is what I do:
String date = new String("01/01/97 12:00:00");
stmt.setObject(1, date);
I tried using TimeStamp's but found I got an occasional Fractional Truncation exception back from the driver. Never had a problem inserting a String using the setObject() method though.
Hope this helps

Similar Messages

  • How do I insert textarea values one at a time into database?

    I have a a simple form:
    Select List - populated by a recordset that gets a list of technicians.   In this format:   Label - >  Tech name   Value - > Tech ID
    Textarea - To paste zip codes into that the tech services.    In this format:   12345,12346,12347,etc..
    When I want to submit the form, I want it to take all of those zip codes and insert them into the database as a single record each with the tech's id from the select list. 
    The code I have is thus:
    $zipcodes = explode(",", $_POST['textarea']);
    $countZips = (count($zipcodes));
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    foreach($zipcodes as $key=>$value)
    while ($countZips >= 1) {
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
      $insertSQL = sprintf("INSERT INTO zip_zip (zip_code, tech_id) VALUES (%s, %s)",
                           GetSQLValueString($value, "int"),
                           GetSQLValueString($_POST['select'], "int"));
      mysql_select_db($database_localhost, $localhost);
      $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
              $countZips--;
    //Done value exists
    //Now moving to next page when done
              $insertGoTo = "index.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      header(sprintf("Location: %s", $insertGoTo));
    //END
    The issue is - let's say I paste 105 zip codes into the text area.   It will insert the FIRST zip code 105 times into the database instead of inserting the 105 zip codes individually.
    Any idea what I'm doing wrong here?
    Thanks!

    Ok, so all of that mysql stuff just needs to be ran once until the connection is closed.  I didn't know that.  That probably makes it run better too.
    Ok, so here is what that code looks like now.  There are a few additions because it turns out I also have to check to make sure the zip code is in a state that the tech is licensed in.  : (  I have a question about how to do that because it is different.  Do I need to post a new question or is better to ask here since my stuff is usually in left field?
    Any way here is my code now.  I think it is much better, right?
    //Start
    //This is my recordset to get the last tech added
    mysql_select_db($database_localhost, $localhost);
    $query_getTechs = "SELECT * FROM zip_tech ORDER BY tech_id DESC";
    $getTechs = mysql_query($query_getTechs, $localhost) or die(mysql_error());
    $row_getTechs = mysql_fetch_assoc($getTechs);
    $totalRows_getTechs = mysql_num_rows($getTechs);
    //This is where I'm getting all zip codes that are serviceable by stupid regulations
    mysql_select_db($database_localhost, $localhost);
    $query_Recordset1 = "SELECT zip_code, state_prefix FROM zip_code";
    $Recordset1 = mysql_query($query_Recordset1, $localhost) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    //ARRAYS
    $results = array();
    $states = array();
    do {
      $results[] = $row_Recordset1['zip_code'];
      $states[] = $row_Recordset1['state_prefix'];
    } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
    //Check if form is filled out
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    //If so, explode textarea values into an array or something
    $zipcodes = explode(",", $_POST['textarea']);
    //MySQL Stuff
    mysql_select_db($database_localhost, $localhost);
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    //my loop to go through each zip code one by one
    foreach($zipcodes as $value)
    //Let's see if the value from the textarea is in our $results array from above
    if (in_array($value, $results)){
    //If it is in the array - then insert it into the database with the tech id
      $insertSQL = sprintf("INSERT INTO zip_zip (zip_code, tech_id) VALUES (%s, %s)",
                           GetSQLValueString($value, "int"),
                           GetSQLValueString($_POST['tech_id'], "int"));
      $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
    //Done value exists
    //Now moving to next page when done
              $insertGoTo = "index.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      header(sprintf("Location: %s", $insertGoTo));
    //END
    Message was edited by: Drymetal

  • Insert date time into oracle database from jsp

    pls tell me ,from jsp how can I insert datetime values into oracle database .I am using oracle 9i .here is codethat i have tried
    html--code
    <select name="date">
    <option selected>dd</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    </select>
    <select name="month">
    <option selected>dd</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    </select>
    <select name="year">
    <option selected>dd</option>
    <option>2004</option>
    <option>2005</option>
    <option>2006</option>
    <option>2007</option>
    </select>
    here the jsp code
    <% date= request.getParameter("date"); %>
    <% month= request.getParameter("month"); %>
    <% year= request.getParameter("year"); %>
    try
    { Class.forName("oracle.jdbc.driver.OracleDriver"); }
    catch (ClassNotFoundException exception)
    try
         Connection connection = null;
         out.println("connectiong the database");
    connection = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcsid","scott","tiger");
    out.println("connection getted");
         int rows = 0;
         String query_2 = "insert into mrdetails values(?)";
         String dob = date+month+year;
         prepstat = connection.prepareStatement(query_2);
         prepstat.setTimestamp(4,dob);
         rows = prepstat.executeUpdate();
         out.println("data updated");
    catch (Exception exception3)
    out.println("Exception raised"+exception3.toString());
    }

    To insert date values into a database, you should use java.sql.Date. If it also has a time component, then java.sql.TimeStamp.
    Your use of prepared statements is good.
    You just need to convert the parameters into a date.
    One way to do this is using java.text.SimpleDateFormat.
    int rows = 0;
    String query_2 = "insert into mrdetails values(?)";
    String dob = date+"/" + month+ "/" + year;
    SimpleDateFormat sdf = new SImpleDateFormat("dd/MM/yyyy");
    java.util.Date javaDate = sdf.parse(dob);
    java.sql.Date sqlDate = new java.sql.Date(javaDate .getTime);
    prepstat = connection.prepareStatement(query_2);
    prepstat.setTimestamp(4,sqlDate);
    rows = prepstat.executeUpdate();
    out.println("data updated");Cheers,
    evnafets

  • Inserting logon date & time into a table

    hi,
    i want to insert the logon date&time into a table which have a field
    called log_track and data type as date. i want to insert the
    information as 'dd/mm/yyyy hh24:mi:ss' . I tried to insert with
    the follwoing
    insert into log_chek values ( to_date(sysdate,'dd/mm/yyyy hh24:mi:ss))
    but it is not taking the time...how to include the time also..? I am using oracle 8i
    thanks in adv
    kris

    Dates are stored as dates. You cannot select to store a date in date format like dd/mm/yyyy hh24:mi:ss. That is not your decision to make. It is stored as a date format as a binary value.
    How you want to view that date, is your decision. How must this binary date format value much be displayed as a text string?
    So, when inserting a date you insert it as a date. That simple.
    insert into log_chek values ( sysdate )
    When you want to view that date, you decide how you would like it to be displayed in human readable format:
    select TO_CHAR( log_date, 'dd/mm/yyyy hh24:mi:ss') as log_date from log_chek

  • FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.

    HI EXPERTS,
         FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.
    PLS DO HELP.....

    Hiii gita
    we have another FM SPELL_AMOUNT
    regards
    Jaipal

  • How to update transaction data automatically into MySQL database using PI

    Dear All,
    With reference to subject matter I want a sincere advice regarding how to update transaction data automatically into MySQL database using PI. Is there any link available where I can get step-by-step process.
    Ex: I have a MYSQL database in my organization. Whenever a delivery created in SAP some fields like DO Number, DO quantity, SO/STO number should get updated in MYSQL database automatically.
    This scenario is related to updation of transactional data into MYSQL DB and I want your suggestions pertaining to same issue.
    Thanks and Regards,
    Chandra Sekhar

    Hi .
    Develop a sceanrio between SAP to Database system,When the data updates in SAP Tables read the data and update it in DATA Base using JDBC adapter,but there will be some delay in updating data in MySQL.
    serach in sdn for IDOC-TOJDBC sceannario,many documents available for the same.
    Regards,
    Raja Sekhar

  • Installation date/time of a database !!

    How can i determine the installation date/time of my databases? I can forget to note the date and time of my database instances. After some time since we have one than more databases, it becomes important to remember thier installation sequence. Thank you very much for your comments.

    If you have never recreated/restored/reincarnated the database, then CREATED column from v$database should tell you when you created the database.
    If you are looking for the date/time of installation of Oracle home, check the logs under OraInventory.

  • Boss is gonna kill me. I Need help inserting a DATE/TIME into MSAccess

    Hello,
    I have spent way to long trying to figure out how to insert a date into the date/time field of a microsoft access database. Could someone please help me figure this out. I know there are a million previous posts about this topic and i looked through a bunch and none of them seem to work... i have tried so many different things. The code i am working (at this point in time.. since it has changed a million times) is:
                             String MYDATE = "yyyy-MM-dd hh:mm:ss a";
                             Date date = new Date();
                             String dateout = new SimpleDateFormat(MYDATE).format(date);
                             System.out.println(" the date is " + dateout);
    Timestamp timeStamp = new Timestamp(date.getTime());
    timeStamp.setNanos(0);
                             System.out.println(" the date is " + timeStamp);
                             String sql2 = "INSERT INTO DATE5 (stuff, date) VALUES ('hello', CVDATE(" + timeStamp + "))";
                             ProblemTrackingDB.DoUpdate(sql2);
                             sql2 = "INSERT INTO DATE5 (stuff, date) VALUES ('hello', '" + dateout + "')";
                             ProblemTrackingDB.DoUpdate(sql2);
    i have tried both of those ways and either work (ie... comment one out and try the other)
    i always get a " Syntax error in INSERT INTO statement" thrown
    i have also tried without the single quotes.
    Any help would Be MUCH appreciated as my boss is starting to get agrivated...
    thanks to anyone who helps,
    Jon

    Change your program to use a PreparedStatement to do this insert. You only need to create a PreparedStatement once, so in your constructor or initializer do this:PreparedStatement insert = connection.PrepareStatement("INSERT INTO DATE5 (stuff, date) VALUES (?, ?)");Then the code to write a record is this:Timestamp timeStamp = new Timestamp(date.getTime());
    timeStamp.setNanos(0);
    insert.setString(1, "hello");
    insert.setTimeStamp(2, timeStamp);
    insert.executeUpdate();That's all. You never need to mess about with formatting timestamps in the way your database needs them, the PreparedStatement takes care of all that for you.

  • How to insert the sysdate time into the database

    hi all,
    when i execute the following query,
    insert into table_name
    (date_field)
    values
    (to_date(sysdate, 'yyyy/mm/dd hh24:mi:ss'));
    The value is inserted as 08-02-12 12:00:00. In this query, it always stores the default time as 12 a.m.
    But i need to insert the original system time not the default one.
    please help me how to rectify it.

    I do not understand as to why you are using the to_date function on sysdate since sysdate is already in date format.
    If date_field is of the data type date, then the following dml should work.
    insert into table_name(date_field) values (sysdate);
    In case date_field is a varchar2 field and you want to store the date and time in a string format, then the following statement should work.
    insert into table_name (date_field)
    values (to_char(sysdate, 'yyyy/mm/dd hh24:mi:ss'));

  • Problem while inserting Date/Time in Oracle Database

    Hai,
    i want to insert the date and time in a date column. here, i am using java.sql.Date and java.sql.Time to assign the date in Prepared Statement.
    PreparedStatement psmt=con.prepareStatement("insert into test(ex_date) values(?)");
    java.util.Calendar c=Calendar.getInstance();
    c.set(2002,2,21,10,10,00);
    java.sql.Date d=new Date(c.getTime().getTime());
    java.sql.Time t=new Time(c.getTime().getTime());
    psmt.clearParameters();
    psmt.setDate(1,d);
    psmt.setDate(1,t);
    psmt.executeUpdate();
    Above program is inserted the Date and time in the database as the following "1900/2/21 10:10 AM"
    but i am giving the year as 2002. it inserted the year as 1900. what is the problem with the code?
    please let me know
    Thanks in advance.
    Regards
    sankarjune14

    Hai Franco,
    i put the wrong code. Here, is the Original Code.
    PreparedStatement psmt=con.prepareStatement("insert into test(ex_date) values(?)");
    java.util.Calendar c=Calendar.getInstance();
    c.set(2002,2,21,10,10,00);
    java.sql.Date d=new Date(c.getTime().getTime());
    java.sql.Time t=new Time(c.getTime().getTime());
    psmt.clearParameters();
    psmt.setDate(1,d);
    psmt.setTime(1,t); // Last time i put psmt.setDate(1,t);
    psmt.executeUpdate();
    and, the getTimeInMillis() method is a protected method in java.util.Calendar class. how can we use it
    please give me some other idea to insert the date and time in oracle database.
    Thanks in advance
    sankarjune14

  • How to insert date/time to sql database

    Hi,
    I would like to insert date and time alongside with my data receiving from the sensor.
    Right now i can insert data into sql table everytime when the data changes but i also wanted to insert the date and time as well.
    Thank you in advance!

    I create a field that is a datetime and set the default value to getdate().  So everytime i make an entry into this database, it automatically adds a datestamp.

  • How to put date&time into a variable from a database?

    In an Oracle table, myDateColumn is 2002-06-25 17:40:55. I can't put it into a variable.
    java.text.SimpleDateFormat dF=new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    rs=stmt.executeQuery("select myDateColumn from myTable");
    rs.next()
    System.out.println(rs.getString(1)); // 2002-06-25 17:40:55 is output
    java.util.Date myDate=rs.getDate(1);
    out.println(dF.format(myDate)); // 25/06/2002 00:00:00 is output
    java.util.Date myDate=rs.getTime(1);
    out.println(dF.format(myDate)); // 01/01/1970 17:40:55 is output
    My question is: How should I put this date (both date and time) into a variable, myDate?

    There are three JDBC types relating to time:
    1] The JDBC DATE type represents a date consisting of day, month, and year. The corresponding SQL DATE type is defined in SQL-92, but it is implemented by only a subset of the major databases. Some databases offer alternative SQL types that support similar semantics.
    2] The JDBC TIME type represents a time consisting of hours, minutes, and seconds. The corresponding SQL TIME type is defined in SQL-92, but it is implemented by only a subset of the major databases. As with DATE, some databases offer alternative SQL types that support similar semantics.
    3] The JDBC TIMESTAMP type represents DATE plus TIME plus a nanosecond field. The corresponding SQL TIMESTAMP type is defined in SQL-92, but it is implemented by only a very small number of databases.
    In ur case pls use:
    java.sql.Timestamp
    good luck !
    ...san :--)

  • Problems converting FILETIME date/time into MM/DD/YYYY format...

    Has anyone successfully converted a FILETIME date/time value into a MM/DD/YYYY format using ColdFusion? I am failing drastically, and it seems like an easy conversion.
    FILETIME format (details: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724284(v=vs.85).aspx) is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
    A database I'm working with has such values, and I want to display them in a user-friendly date format within my application.
    For example, one record is:
    13003368600
    The above number represents the following date and time:
    1/22/2013 @ 2:50 PM
    Sadly I know this only because the FILETIME value gets written to the database by a third-party application, and within that application I specify it in the MM/DD/YYYY format.
    Can anyone offer me some guidance, or better yet has anyone accomplished this already and want to share code?

    I did this, on cf9/linux, and it seemed to do the trick:
    <cfscript>
    Long = createObject("java","java.lang.Long");
    Date = createObject("java","java.util.Date");
    fileTimeToEpoch =
    // take pwdLastSet From Active Directory, it's in filetime
    pwdLastSet = JavaCast("long", Long.parseLong("130292682204519505"));
    // take filetime and turn it into epoch/java - 1970/1/1
    // http://www.silisoftware.com/tools/date.php - converted: jan 1, 1970 00:00 -00
    javaTime = JavaCast("long", pwdLastSet - 116444736000000000);
    // convert to milliseconds
    javaTime = JavaCast("long", javaTime / 10000);
    today = JavaCast("string", Date.init(javaTime));
    </cfscript>
    <cfdump var="#pwdLastSet#">
    <cfdump var="#javatime#">
    <cfdump var="#today#">

  • Converting Delivery Creation Date/Time into the Local Date/Time

    Hi
    I have two fields like 'Delivery Creation Date' and 'Delivery Creation Time' in ECC system . My user wants the Delivery Creation Date / Delivery Creation Time in Local time of Plants .
    For example :
    Delivery    Plant       DelivCreationDate       DelivCreationTime   DelivCreationDate(Local)   DelivCreationTime(Local)
    312456          1650               11/2/2007                     4:30                          11/2/2007                          3:30
    Here the Plant 1650 is in Mexico . The above delivery is created in Canada in ECC system according to the candain time .
    But user wants to convert the Candain Delivery Creation Date and Time into the Local Date/Time of specific plant .
    So we need to convert the  Candain Delivery Creation Date and Time into Mexico timings .
    How can it is possible this one and user wants to automate this process .
    Please let me know
    Mubeen

    DATA :
    timestamp like TZONREF-TSTAMPS,
    time like sy-uzeit,
    date like sy-datum.
    The following function module is used to convert the
    time and date into GMT timestamp
    CALL FUNCTION 'IB_CONVERT_INTO_TIMESTAMP'
    EXPORTING
    i_datlo = <source_fields>-delivery_date
    i_timlo = <source_fields>-delivery_time
    I_TZONE = CAD'
    IMPORTING
    E_TIMESTAMP = timestamp.
    The following function module is used to convert the
    above obtained timestamp to MEX  timezone date and time.
    CALL FUNCTION 'IB_CONVERT_FROM_TIMESTAMP'
    EXPORTING
    i_timestamp = timestamp
    I_TZONE = MEX
    IMPORTING
    E_DATLO = date
    E_TIMLO = time.
    CAD and MEX are variables i have used...
    the challenge is to find the canadian and mexican time zone....CAD and MEX.
    which you can get by performing a lookup in table T001W and passing country as parameter.

  • How do you split a list of dates/times into weeks?

    Hello all,
    I am trying to make a time management spreadsheet that will keep track of my odd hours at my workplace. What I want to do is have one table with all of my date/times in and out, hours worked, and notes, that is then linked to a form. In a second table, I'd like to tablulate my week-by-week totals as well as monthly leave totals (sick/annual leave). What I can't work out is if you can make a table that automatically calculates a total number of hours for a week/month. So for example, if I have all my work from January through March in my first table, that the second table would be able to split that sheet into week-long sections and calculate the total number of hours worked for each week. Is such a thing possible in Numbers? Am I making sense? Thanks for the help!

    =SUMIF(Work Times::C2:C84,Work Times::A2:A84,>=A14,Work Times::A2:A84,<=B14) returns a syntax error.
    I won't have and opportunity to test here, but I think you need to add double quotes and concatenate, e.g.
    >=A14
    should be
    ">="&A14
    etc.
    And you need to use SUMIFS if you have more than one column-criterion pair.
    SG

Maybe you are looking for

  • Process order settlement for materialwith 2 valuation types

    Hi , In chemical mfg scenario there is co product which has 2 valuation types. The cost of mfg to be split i nratio of 60 :40 .  But this co product has 2 valaution types and hence there is problem in order settlement .In the settement rule there is

  • Using flash projector on multiple screens

    hi, i have a display project for which i will be using 4 plasma screens linked together as 1 giant screen. I'm not sure if flash's "full screen" mode will work...and i don't know of any 3rd party software off the top of my head that will work... can

  • Imac G5 bad caps advice

    I have an iMac G5 20" iSight 2.1GHz that stopped working. Made a loud pop one day and shut off. Upon restart it chimes, fan roars, and screen stays black. I've pulled the logic board and power supply for inspection. On the logic board one, and only o

  • Oracle Pricing- Using Discount Feature

    Hi, I'm Anil Wadhwa and i'm working for Amtrex Hitachi Appliances ltd., Ahmedabad (India). I'm handling the OM Module and I was trying to use the Discount feature availabe in the Oracle Advanced Pricing. As of now we have defined a modifier which we

  • SMP 2.3 Issue on choice field

    iam working on hybrid app in SMP 2.3. i have some issue on  it . i run the app first time select the choice field it will show at  empty after click on outer space and then click the choice field again it shows the data but my need is first time to s