title: How to get a Date object in q when inserting from Java
body: <p>According to <a href="http://code.kx.com/wiki/JB:QforMortals2/atoms#Overview" rel="nofollow noreferrer">QforMortals2</a>, the equivalent representation of q's <code>date</code> is <code>java.util.Date</code>.
  Likewise, q's <code>datetime</code> is equal to <code>java.sql.Timestamp</code>.</p>
  
  <p>However, when I push a table from Java to q, q automatically converts the <code>java.util.Date</code> object to a <code>datetime</code> object, which also has the time included. I then tried to push the object as being <code>java.sql.Date</code> and the same thing happened: again q recognised it as a <code>datetime</code> atom.</p>
  
  <p>How can I pass Java's <code>Date</code> object to q such that q recognised it correctly (without the time)?</p>
  
  <p>Note: I'd rather not specify the table's format beforehand [<code>"d"$()</code>], but would rather have that q automatically recognizes the object correctly.</p>
  
  <h2>Update [solved]</h2>
  
  <p>Thanks to <a href="https://stackoverflow.com/users/2393012/user2393012">user2393012</a> I found my error.</p>
  
  <p>First of all, q does not accept inserts into an undefined table directly. However, when you call upon a process <code>a</code> which in turn performs an insert into a process <code>b</code>, it <strong>does</strong> allow inserts into undefined tables. </p>
  
  <p>E.g. define a process <code>b</code> with <code>\p 5002</code>, and define a process <code>a</code> with:</p>
  
  <pre><code>\p 5001
  h:hopen `::5002;
  .u.upd:{[x;y] h (insert; x; y)};
  </code></pre>
  
  <p>Now when calling <code>.u.upd</code>, it is actually possible to insert into an undefined table in process <code>b</code>.</p>
  
  <p>Now when using <code>c.ks(Object)</code>, the object should consist of <strong>arrays</strong> which hold the data.</p>
  
  <p>My error was that I defined the data array as </p>
  
  <pre><code>new Date[] {new java.sql.Date(new java.util.Date().getTime())}
  </code></pre>
  
  <p>opposed to:</p>
  
  <pre><code>new java.sql.Date[] {new java.sql.Date(new java.util.Date().getTime())}
  </code></pre>
  
  <p>Therefore, the <code>java.sql.Date</code> got parsed back into a <code>java.util.Date</code> when putting it in the array.</p>
  
  <p>The following Java code therefore works as expected:</p>
  
  <pre><code>import java.io.IOException;
  import kx.c;
  import kx.c.*;
  
  public class testingDate {
  
      public static c conn;
  
      public static void main(String[] args) throws KException, IOException {
  
          Object[] data     = new Object[] {new java.sql.Date[] {new java.sql.Date(new java.util.Date().getTime())}};
          c.Flip tab        = new c.Flip(new c.Dict(new String[] {"date"}, data));
          Object[] updquery = new Object[] { ".u.upd", "test", tab };
  
          conn = new c("localhost", 5001);
  
          try {
              conn.k(updquery);
          } catch (IOException e) {
              System.err.println("error sending data to server.");
          }   
      }
  }
  </code></pre>
  
  <p>Which saves the table <code>test</code> in process <code>b</code> with content:</p>
  
  <pre><code>date      
  ----------
  2015.03.10
  </code></pre>