Index: src/edu/ucsb/nceas/metacat/DocumentImpl.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 6019)
+++ src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 6020)
@@ -45,6 +45,7 @@
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.Timestamp;
+import java.util.Calendar;
 import java.util.Hashtable;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -55,6 +56,8 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.xml.bind.DatatypeConverter;
+
 import edu.ucsb.nceas.metacat.accesscontrol.AccessControlInterface;
 import edu.ucsb.nceas.metacat.accesscontrol.AccessControlList;
 import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
@@ -2692,6 +2695,9 @@
                     conn.commit();
                     conn.setAutoCommit(true);
                     
+                    // update the node data to include numeric and date values
+                    updateNodeValues(conn, docid);
+                    
                     //write the file to disk
                     logMetacat.debug("DocumentImpl.write - Writing xml to file system");                    
                 	writeToFileSystem(xmlString, accnum, encoding);
@@ -2777,8 +2783,10 @@
             conn.commit();
             conn.setAutoCommit(true);
             
+            //update nodes
+            updateNodeValues(conn, docid);
+            
             //write the file to disk
-
         	writeToFileSystem(xmlString, accnum, encoding);
 
             addDocidToIndexingQueue(docid, rev);
@@ -3703,6 +3711,71 @@
        
     }
     
+    private static void updateNodeValues(DBConnection dbConnection, String docid) throws SQLException {
+    	PreparedStatement sqlStatement = null;
+        PreparedStatement pstmt = null;
+        ResultSet rset = null;
+
+        sqlStatement = dbConnection.prepareStatement(
+        		"SELECT DISTINCT NODEID, NODEDATA "
+                + "FROM xml_nodes "
+                + "WHERE nodedata IS NOT NULL "
+                + "AND docid = ?");
+        sqlStatement.setString(1, docid);
+        rset = sqlStatement.executeQuery();
+
+        int count = 0;
+        while (rset.next()) {
+
+            String nodeid = rset.getString(1);
+            String nodedata = rset.getString(2);
+
+            try {
+                if (!nodedata.trim().equals("")) {
+                	System.out.println(nodedata);
+                	
+                	try {
+                		double dataNumeric = Double.parseDouble(nodedata);
+	                    pstmt = dbConnection.prepareStatement(
+	                        "UPDATE xml_nodes " +
+	                        " SET nodedatanumerical = ?" +
+	                        " WHERE nodeid = " + nodeid);
+	                    pstmt.setDouble(1, dataNumeric);
+	                    pstmt.execute();
+	                    pstmt.close();
+                	} catch (Exception e) {
+                		// try a date
+                		try {
+	                		Calendar dataDateValue = DatatypeConverter.parseDateTime(nodedata);
+		                    Timestamp dataTimestamp = new Timestamp(dataDateValue.getTimeInMillis());
+		                    pstmt = dbConnection.prepareStatement(
+		                        "UPDATE xml_nodes " +
+		                        " SET nodedatadate = ?" +
+		                        " WHERE nodeid = " + nodeid);
+		                    pstmt.setTimestamp(1, dataTimestamp);
+		                    pstmt.execute();
+		                    pstmt.close();
+                		} catch (Exception e2) {
+							// we are done with this node
+						} 
+					}
+
+                    count++;
+                    if (count%5 == 0) {
+                        System.out.println(count + "...");
+                    }
+            		
+                }
+            } catch (Exception e) {
+            	// do nothing, was not a valid date
+            	e.printStackTrace();
+            } 
+        }
+
+        rset.close();
+        sqlStatement.close();
+    }
+    
     private static void moveNodesToNodesRevision(DBConnection dbconn,
                                        long rootNodeId) throws Exception
     {
Index: src/edu/ucsb/nceas/metacat/DBSAXNode.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBSAXNode.java	(revision 6019)
+++ src/edu/ucsb/nceas/metacat/DBSAXNode.java	(revision 6020)
@@ -26,12 +26,13 @@
 
 package edu.ucsb.nceas.metacat;
 
-import java.sql.*;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Enumeration;
 import java.util.Hashtable;
-import java.util.Enumeration;
+
 import org.apache.log4j.Logger;
 import org.xml.sax.SAXException;
 
@@ -176,7 +177,6 @@
     {
 
       PreparedStatement pstmt;
-      Timestamp timestampData = null;
       
       if (nodetype == "DOCUMENT") {
         pstmt = connection.prepareStatement(
@@ -184,57 +184,18 @@
             "(nodetype, nodename, nodeprefix, docid) " +
             "VALUES (?, ?, ?, ?)");
 
-        // Increase DBConnection usage count
-        connection.increaseUsageCount(1);
         logMetacat.debug("DBSAXNode.writeChildNodeToDBDataLimited - inserting doc name: " + nodename);
       } else {
-          if(data != null && !data.trim().equals("")
-             && !data.trim().equals("NaN") && !data.trim().equalsIgnoreCase("Infinity")){
-        	  try{
-        		  // try some common ISO 8601 formats
-        		  SimpleDateFormat sdf = null;
-        		  if (data.length() == 10) {
-        			  sdf = new SimpleDateFormat("yyyy-MM-dd");
-        		  } else if (data.length() == 19) {
-        			  sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
-        		  } else {
-        			  // throw this so we continue with parsing as numeric or string.
-        			  throw new ParseException("String length will not match date/dateTime patterns", -1);
-        		  }
-        		  Date dateData = sdf.parse(data);
-        		  timestampData = new Timestamp(dateData.getTime());
-                  pstmt = connection.prepareStatement(
-                      "INSERT INTO xml_nodes " +
-                      "(nodetype, nodename, nodeprefix, docid, " +
-                      "rootnodeid, parentnodeid, nodedata, nodeindex, nodedatadate) " +
-                      "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
-              } catch (ParseException pe) {
-	        	  try{
-	                  double numberData = Double.parseDouble(data);
-	                  pstmt = connection.prepareStatement(
-	                      "INSERT INTO xml_nodes " +
-	                      "(nodetype, nodename, nodeprefix, docid, " +
-	                      "rootnodeid, parentnodeid, nodedata, nodeindex, nodedatanumerical) " +
-	                      "VALUES (?, ?, ?, ?, ?, ?, ?, ?, "+ numberData +")");
-	              } catch (NumberFormatException nfe) {
-	                  pstmt = connection.prepareStatement(
-	                      "INSERT INTO xml_nodes " +
-	                      "(nodetype, nodename, nodeprefix, docid, " +
-	                      "rootnodeid, parentnodeid, nodedata, nodeindex) " +
-	                      "VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
-	              }
-              }
-          } else {
-              pstmt = connection.prepareStatement(
-                  "INSERT INTO xml_nodes " +
-                  "(nodetype, nodename, nodeprefix, docid, " +
-                  "rootnodeid, parentnodeid, nodedata, nodeindex) " +
-                  "VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
-          }
-        // Increase DBConnection usage count
-        connection.increaseUsageCount(1);
+          pstmt = connection.prepareStatement(
+              "INSERT INTO xml_nodes " +
+              "(nodetype, nodename, nodeprefix, docid, " +
+              "rootnodeid, parentnodeid, nodedata, nodeindex) " +
+              "VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
       }
-
+      
+      // Increase DBConnection usage count
+      connection.increaseUsageCount(1);
+      
       // Bind the values to the query
       pstmt.setString(1, nodetype);
       int idx;
@@ -259,9 +220,6 @@
           pstmt.setInt(8, incChildNum());
         }
       }
-      if (timestampData != null) {
-    	  pstmt.setTimestamp(9, timestampData);
-      }
       // Do the insertion
       logMetacat.debug("DBSAXNode.writeChildNodeToDBDataLimited - SQL insert: " + pstmt.toString());
       pstmt.execute();
@@ -271,7 +229,6 @@
       nid = DatabaseService.getInstance().getDBAdapter().getUniqueID(connection.getConnections(), "xml_nodes");
       //should increase connection usage!!!!!!
 
-
       if (nodetype.equals("DOCUMENT")) {
         // Record the root node id that was generated from the database
         setRootNodeID(nid);
@@ -356,47 +313,13 @@
     {
 
       PreparedStatement pstmt;
-      Timestamp timestampData = null;
       logMetacat.info("DBSAXNode.writeDTDNodeToDB - Insert dtd into db: "+nodename +" "+data);
-      if(data != null && !data.trim().equals("")){
-    	  try{
-    		  // try some common ISO 8601 formats
-    		  SimpleDateFormat sdf = null;
-    		  if (data.length() == 10) {
-    			  sdf = new SimpleDateFormat("yyyy-MM-dd");
-    		  } else if (data.length() == 19) {
-    			  sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
-    		  }
-    		  Date dateData = sdf.parse(data);
-    		  timestampData = new Timestamp(dateData.getTime());
-              pstmt = connection.prepareStatement(
-                  "INSERT INTO xml_nodes " +
-                  "(nodetype, nodename, docid, " +
-                  "rootnodeid, parentnodeid, nodedata, nodeindex, nodedatadate) " +
-                  "VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
-          } catch (ParseException pe) {
-    	  	try{
-                double numberData = Double.parseDouble(data);
-                pstmt = connection.prepareStatement(
-                    "INSERT INTO xml_nodes " +
-                    "(nodetype, nodename, docid, " +
-                    "rootnodeid, parentnodeid, nodedata, nodeindex, nodedatanumerical) " +
-                    "VALUES (?, ?, ?, ?, ?, ?, ?, "+ numberData +")");
-            } catch (NumberFormatException nfe) {
-                pstmt = connection.prepareStatement(
-                    "INSERT INTO xml_nodes " +
-                    "(nodetype, nodename,  docid, " +
-                    "rootnodeid, parentnodeid, nodedata, nodeindex) " +
-                    "VALUES (?, ?, ?, ?, ?, ?, ?)");
-            }
-          }
-        } else {
-            pstmt = connection.prepareStatement(
-                  "INSERT INTO xml_nodes " +
-                  "(nodetype, nodename, docid, " +
-                  "rootnodeid, parentnodeid, nodedata, nodeindex) " +
-                  "VALUES (?, ?, ?, ?, ?, ?, ?)");
-        }
+  
+      pstmt = connection.prepareStatement(
+              "INSERT INTO xml_nodes " +
+              "(nodetype, nodename, docid, " +
+              "rootnodeid, parentnodeid, nodedata, nodeindex) " +
+              "VALUES (?, ?, ?, ?, ?, ?, ?)");
 
        // Increase DBConnection usage count
       connection.increaseUsageCount(1);
@@ -409,9 +332,6 @@
       pstmt.setLong(5, getParentID());
       pstmt.setString(6, data);
       pstmt.setInt(7, getNodeIndex());
-      if (timestampData != null) {
-    	  pstmt.setTimestamp(8, timestampData);
-      }
 
       // Do the insertion
       pstmt.execute();
@@ -419,7 +339,6 @@
 
       // get the generated unique id afterward
       nid = DatabaseService.getInstance().getDBAdapter().getUniqueID(connection.getConnections(), "xml_nodes");
-      //should incease connection usage!!!!!!
 
     } catch (SQLException e) {
       System.out.println("Error in DBSaxNode.writeDTDNodeToDB");
Index: src/edu/ucsb/nceas/metacat/QueryTerm.java
===================================================================
--- src/edu/ucsb/nceas/metacat/QueryTerm.java	(revision 6019)
+++ src/edu/ucsb/nceas/metacat/QueryTerm.java	(revision 6020)
@@ -29,14 +29,14 @@
 
 package edu.ucsb.nceas.metacat;
 
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.util.Calendar;
 import java.util.Vector;
+
+import javax.xml.bind.DatatypeConverter;
+
 import org.apache.log4j.Logger;
 
 import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
-import edu.ucsb.nceas.metacat.util.MetacatUtil;
 import edu.ucsb.nceas.metacat.util.SystemUtil;
 
 /** a utility class that represents a single term in a query */
@@ -212,32 +212,24 @@
                 return null;
             }
             
+            
             try {
-            	// try some common ISO 8601 formats
-        		SimpleDateFormat sdf = null;
-        		if (casevalue.length() == 10) {
-        			sdf = new SimpleDateFormat("yyyy-MM-dd");
-        		} else if (casevalue.length() == 19) {
-        			sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
-        		}
-        		Date dataDateValue = sdf.parse(casevalue);
-                nodedataterm = "nodedatadate";
-        		searchexpr = 
-        			nodedataterm + " " + oper + " '"
-        			+ casevalue + "' ";
-        	} catch (ParseException pe) {
-	            try {
-	                // it is number; numeric comparison
-	                // but we need to make sure there is no string in node data
-	                searchexpr = nodedataterm + " " + oper + " "
-	                        + new Double(casevalue) + " ";
-	            } catch (NumberFormatException nfe) {
-	                // these are characters; character comparison
-	                searchexpr = nodedataterm + " " + oper + " '" + casevalue
-	                        + "' ";
-	            }
-        	}
-            
+                // it is number; numeric comparison
+                searchexpr = nodedataterm + " " + oper + " " + new Double(casevalue) + " ";
+            } catch (NumberFormatException nfe) {
+            	// is it a date?
+            	try {
+                	// try ISO 8601 formats
+                	Calendar dataDateValue = DatatypeConverter.parseDateTime(casevalue);
+                	String lexicalString = DatatypeConverter.printDateTime(dataDateValue);
+                    nodedataterm = "nodedatadate";
+            		searchexpr = 
+            			nodedataterm + " " + oper + " '" + lexicalString + "' ";
+            	} catch (Exception pe) {
+            		// these are characters; character comparison
+                    searchexpr = nodedataterm + " " + oper + " '" + casevalue + "' ";
+            	}
+            }
         }
 
 
Index: src/edu/ucsb/nceas/metacat/admin/upgrade/Upgrade1_10_0.java
===================================================================
--- src/edu/ucsb/nceas/metacat/admin/upgrade/Upgrade1_10_0.java	(revision 6019)
+++ src/edu/ucsb/nceas/metacat/admin/upgrade/Upgrade1_10_0.java	(revision 6020)
@@ -33,10 +33,10 @@
 import java.sql.Statement;
 import java.sql.DriverManager;
 import java.sql.Timestamp;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.util.Calendar;
 
+import javax.xml.bind.DatatypeConverter;
+
 import edu.ucsb.nceas.metacat.admin.AdminException;
 import edu.ucsb.nceas.metacat.properties.PropertyService;
 import edu.ucsb.nceas.utilities.SortedProperties;
@@ -84,35 +84,29 @@
 		
 		            try {
 		                if (!nodedata.trim().equals("")) {
-		                	boolean skip = false;
-		                	SimpleDateFormat sdf = null;
-		            		if (nodedata.length() == 10) {
-		            			sdf = new SimpleDateFormat("yyyy-MM-dd");
-		            		} else if (nodedata.length() == 19) {
-		            			sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
-		            		} else {
-		            			skip = true;
-		            		}
-		            		if (!skip) {
-			            		Date dataDateValue = sdf.parse(nodedata);
-			                    Timestamp dataTimestamp = new Timestamp(dataDateValue.getTime());
-			
-			                    pstmt = sqlca.prepareStatement(
-			                        "update " + tableName +
-			                        " set nodedatadate = ?" +
-			                        " where nodeid = " + nodeid);
-			                    pstmt.setTimestamp(1, dataTimestamp);
-			                    pstmt.execute();
-			                    pstmt.close();
-			
-			                    count++;
-			                    if (count%5 == 0) {
-			                        System.out.println(count + "...");
-			                    }
-		            		}
+		                	
+		                	System.out.println(nodedata);
+		                	
+		            		Calendar dataDateValue = DatatypeConverter.parseDateTime(nodedata);
+		                    Timestamp dataTimestamp = new Timestamp(dataDateValue.getTimeInMillis());
+		
+		                    pstmt = sqlca.prepareStatement(
+		                        "update " + tableName +
+		                        " set nodedatadate = ?" +
+		                        " where nodeid = " + nodeid);
+		                    pstmt.setTimestamp(1, dataTimestamp);
+		                    pstmt.execute();
+		                    pstmt.close();
+		
+		                    count++;
+		                    if (count%5 == 0) {
+		                        System.out.println(count + "...");
+		                    }
+		            		
 		                }
-		            } catch (ParseException pe) {
-		            	// do nothing, was not a date
+		            } catch (Exception e) {
+		            	// do nothing, was not a valid date
+		            	e.printStackTrace();
 		            } 
 		        }
 		        System.out.println("Table: " + tableName + " complete. " + count + " values converted.");
@@ -141,6 +135,10 @@
 			// now run it
             Upgrade1_10_0 upgrader = new Upgrade1_10_0();
             upgrader.upgrade();
+            
+            Calendar date = DatatypeConverter.parseDate("2011-03-17");
+            System.out.println("date:" + DatatypeConverter.printDate(date));
+            
         } catch (Exception ex) {
             System.out.println("Exception:" + ex.getMessage());
             ex.printStackTrace();
