title: google datastore Insert Date as null value using java
body: <pre><code>package com.example.guestbook;
  
  import com.google.appengine.api.datastore.DatastoreService;
  import com.google.appengine.api.datastore.DatastoreServiceFactory;
  import com.google.appengine.api.datastore.Entity;
  
  import java.io.IOException;
  import java.util.Date;
  
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
   Key addTask(String description, DateTime receiveddate) {
               Key key = datastore.allocateId(keyFactory.newKey());
            Entity task = Entity.newBuilder(key)
              .set("description", StringValue.newBuilder(description).
        setExcludeFromIndexes(true).build())
              .set("receiveddate",(receiveddate))    
              .set("created", DateTime.now())
              .set("done", false)
           .build();
          datastore.put(task);
      return key;
       }
      void handleCommandLine(String commandLine) {
      String[] args = commandLine.split("\\s+");
  
      if (args.length &lt; 1) {
        throw new IllegalArgumentException("not enough args");
      }
  
      String command = args[0];
      switch (command) {
        case "new":
  
          args = commandLine.split("\\s+", 3);
          if (args.length != 3) {
            throw new IllegalArgumentException("missing description");
          }
          addTask(args[1],DateTime.copyFrom());
          System.out.println("task added");
          break;
       public static void main(String[] args) throws Exception {
      TaskList taskList = new TaskList();
      System.out.println("Cloud Datastore Task List");
      System.out.println();
      printUsage();
      while (true) {
        String commandLine = System.console().readLine("&gt; ");
        if (commandLine.trim().isEmpty()) {
          break;
        }
        try {
          taskList.handleCommandLine(commandLine);
        } catch (IllegalArgumentException e) {
          System.out.println(e.getMessage());
          printUsage();
        }
      }
      System.out.println("exiting");
      System.exit(0);
     }
  
      private static void printUsage() {
      System.out.println("Usage:");
      System.out.println();
      System.out.println("  new &lt;description&gt;  Adds a task with a description         &lt;description&gt;");
       System.out.println("  done &lt;task-id&gt;     Marks a task as done");
       System.out.println("  list               Lists all tasks by creation time");
       System.out.println("  delete &lt;task-id&gt;   Deletes a task");
         System.out.println();
       }
      }
  </code></pre>
  
  <p>Trying to insert DateTime field as 0 or null value for a partiular record While using Google Cloud Datastore, I need to insert a few records into the database with NULL as the date value. I've tried different ways but it is reflecting errors in inserting.
          /*</p>
  
  <pre><code>  As per this link  https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/datastore/src/main/java/com/google/datastore/snippets/TaskList.java
  </code></pre>