title: How to delete all entities with a timestamp more than 1 day old from Azure Storage Table?
body: <p>Azure storage tables all have a timestamp column.  Based on documentation <a href="https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-tables/#delete-an-entity" rel="noreferrer">here</a> the listed way to delete from a storage table is to select an entity then delete it.  </p>
  
  <p>Does anyone know how to delete any entity from a storage table based on a datetime comparison on the timestamp value using code?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Based on the advice given I wrote the following code.  However, it throws a Bad Request exception on my table.ExecuteQuery(rangeQuery) call.  Any advice?</p>
  
  <pre><code>    StorageCredentials creds = new StorageCredentials(logAccountName, logAccountKey);
      CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
  
      CloudTableClient client = account.CreateCloudTableClient();
  
      CloudTable table = client.GetTableReference(LogTable);
  
      TableQuery&lt;CloudQuerySummary&gt; rangeQuery = new TableQuery&lt;CloudQuerySummary&gt;()
          .Where(TableQuery.GenerateFilterCondition("Timestamp", QueryComparisons.LessThan
          , DateTime.Now.AddHours(- DateTime.Now.Hour).ToString()));
  
  
      TableOperation deleteOperation;
      // Loop through the results, displaying information about the entity.
      foreach (CloudQuerySummary entity in table.ExecuteQuery(rangeQuery))
      {
          deleteOperation = TableOperation.Delete(entity);
  
          table.Execute(deleteOperation);
      }
  </code></pre>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Here is the final working code for anyone who chooses to copy/reference it.</p>
  
  <pre><code>public void DeleteLogsNotFromToday()
  {
      StorageCredentials creds = new StorageCredentials(logAccountName, logAccountKey);
      CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
  
      CloudTableClient client = account.CreateCloudTableClient();
  
      CloudTable table = client.GetTableReference(LogTable);
  
      TableQuery&lt;CloudQuerySummary&gt; rangeQuery = new TableQuery&lt;CloudQuerySummary&gt;()
          .Where(TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.LessThan
          , DateTime.Now.AddHours(-DateTime.Now.Hour)));
  
      try
      {
  
          TableOperation deleteOperation;
          // Loop through the results, displaying information about the entity.
          foreach (CloudQuerySummary entity in table.ExecuteQuery(rangeQuery))
          {
              deleteOperation = TableOperation.Delete(entity);
  
              table.Execute(deleteOperation);
          }
      }
      catch (Exception ex)
      {
          throw;
      }
  
  }
  </code></pre>