title: AnnotationChart dateformat from sqlserver
body: <p>Hi Im trying to implement an Annotation chart that get its data from Sql Server. The code is working as the data is coming back . My problem is the format of the date / datetime when doing google.visualization.DataTable().addRow()</p>
  
  <p>The date format returned from sqlserver is 2014-03-19 12:00:00 AM</p>
  
  <p>How to change this date format to insert into the datatable.</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;
  
  &lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;script src="js/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script type='text/javascript' src='http://www.google.com/jsapi'&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          google.load('visualization', '1.1', { packages: ['annotationchart'] });
      &lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              $.ajax({
                  type: 'POST',
                  dataType: 'json',
                  contentType: 'application/json',
                  url: 'Default.aspx/GetData',
                  data: '{}',
                  success:
                      function (response) {
                          drawVisualization(response.d);
                      }
  
              });
          })
  
          function drawVisualization(dataValues) {
              var data = new google.visualization.DataTable();
              data.addColumn('datetime', 'Column Name');
              data.addColumn('number', 'Column Value');
              data.addColumn('number', 'Column Value2');
  
              console.log(dataValues[0].ColumnName);
  
  
  
              for (var i = 0; i &lt; dataValues.length; i++) {
                  data.addRow([dataValues[i].ColumnName, dataValues[i].Value, dataValues[i].Value2]);
              }
  
  
             var formatter = new google.visualization.DateFormat({pattern: 'yyyy-MM-dd'});
  
                   var chart = new google.visualization.AnnotationChart(document.getElementById('visualization'));
  
          var options = {
            displayAnnotations: false,
          };
  
          chart.draw(data, options);
  
  
  
           }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div id="visualization" style="width: 1000px; height: 500px;"&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is the C# code behind</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Data;
  using System.Data.SqlClient;
  using System.Web.Services;
  using System.Configuration;
  public partial class _Default : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
      }
  
      [WebMethod]
      public static List&lt;Data&gt; GetData()
      {
  
          SqlConnection conn = new SqlConnection(****);
          DataSet ds = new DataSet();
          DataTable dt = new DataTable();
          conn.Open();
          string cmdstr = "select LogDate, val1, val2from [vwTest]";
  
          SqlCommand cmd = new SqlCommand(cmdstr, conn);
          SqlDataAdapter adp = new SqlDataAdapter(cmd);
          adp.Fill(ds);
          dt = ds.Tables[0];
          List&lt;Data&gt; dataList = new List&lt;Data&gt;();
          string cat = "";
          int val = 0;
          int val2 = 0;
          foreach (DataRow dr in dt.Rows)
          {
              cat = dr[0].ToString();
              val = Convert.ToInt32(dr[1]);
              val2 = Convert.ToInt32(dr[2]);
              DateTime dte = DateTime.Parse(DateTime.Parse(cat).ToString("yyyy-MM-dd"));
              dataList.Add(new Data(dte, val, val2));//Dont know what to do here
          }
          return dataList;
      }
  
      public class Data
      {
          public DateTime ColumnName;
          public int Value = 0;
          public int Value2 = 0;
          public Data(DateTime columnName, int value, int value2)
          {
              ColumnName = columnName;
              Value = value;
              Value2 = value2;
          }
      }
  }
  </code></pre>
  
  <p>I see examples where people use new Date(2013,23,3,4,5) say but im not hard coding my data.</p>
  
  <p>Please assist. This is my first Attempt at Google Visualization API</p>