title: Dealing with Cassandra Timestamp
body: <p>Recently I have started working on cassandra and I have some issues dealing with cassandra timestamp using cql and Java. </p>
  
  <p>Below is my sample cassandra table schema.</p>
  
  <pre><code>CREATE TABLE emp (
      empid int,
      create_date timestamp,
      deptid int,
      PRIMARY KEY (empid, create_date)
  )
  </code></pre>
  
  <p>Here are my questions below:</p>
  
  <p><strong>1)</strong> Actually I need only date(I am not worried about time), In my table schema I have used timestamp datatype, Is there any datatype like date to store only date instead timestamp.</p>
  
  <p><strong>2)</strong> If there is no alternative to timestamp datatype below is how I am inserting record into table manually </p>
  
  <pre><code>Insert into emp(empId, deptId, create_date) values(1,2,'2016-03-15 00:00:00+0000');
  </code></pre>
  
  <p>When I am trying to query to retrieve record using cql as below </p>
  
  <pre><code>select * from emp where create_date='2016-03-15' and empid=1;
  </code></pre>
  
  <p>It's not returning any record so I have use below query</p>
  
  <pre><code> select * from emp where create_date='2016-03-15 00:00:00+0000' and empid=1;
  </code></pre>
  
  <p>above query returned record, So how to query so that I need to get records only with date.</p>
  
  <p><strong>3)</strong> I am using datastax 2.1 JAVA API to communicate to cassandra, Below is my code how I am retrieving timestamp column from Java.</p>
  
  <pre><code>row.getDate("create_date")
  </code></pre>
  
  <p>getDate method is returning java.util.date (later versions returning <strong>com.datastax.driver.core.LocalDate</strong>)</p>
  
  <p>When I try to get date from code its returning one day less suppose if record in my table is <strong>2016-03-15 00:00:00+0000</strong>, but from my code it shows something like <strong>2016-03-14 EDT</strong> (one day less is this because of timezone issue), If its timezone issue should I set timezone in my Java code while retrieving</p>
  
  <p><strong>4)</strong> If I want to query and get record from my Java code based on empId and create_date how to make exact pattern like <code>2016-03-15 00:00:00+0000</code> in Java code, As it is not retrieving if I provide only date in where condition or is there any better way in retrieving using Java code.</p>