Amazon Web Services   |   Tuesday, January 13, 2009 @ 11:11 PM EST
  print view | pdf
  permalink

Amazon stores everything as strings in their SimpleDB (strings = simple).  Because of this there are some gotchas when it comes to string comparisons. 

How to compare dates?

In order to compare dates you need to convert and store the date as an ISO8601 formatted string.  An easy solution is to call a function right before you write to SimpleDB.  In my case I call a function that takes in a .NET DateTime and converts it to ISO8601.

   1: public static String ConvertDateTimeToISO8601(DateTime dt)
   2: {
   3:     return dt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'");
   4: }

On the flipside, when you need to read it from SDB, use the ISO8601 to DateTime to bring it back to a C# friendly object, DateTime.

   1: public static DateTime ConvertISO8601ToDateTime(String iso)
   2: {
   3:     return DateTime.ParseExact(iso, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", System.Globalization.CultureInfo.InvariantCulture);
   4: }

As documented in Amazon’s Tips and Tricks posting, you can also send a ISO8601 formatted query to SDB to pull down a collection of objects matching a date filter.  (ie. ['Update Date' > '2008-01-24T22:48:15+01:00'])

Once you, as a developer, get used to converting objects to strings (and vice-versa), working with Amazon SimpleDB becomes much easier.

Comments are closed

YOUR CRUMBS

[X]

SITE SEARCH powered by google

SITE POWERED BY

RECENT TWEETS (TWITTER)

  • "Attending a Microsoft Sharepoint training class all week"
    about 358 days ago
  • "Glued to the tv watching UConn and Syracuse now in 5th OT"
    about 362 days ago
  • "@microplaza nice!"
    about 370 days ago
  • RANDOM VIDEO CLIP

    ABOUT ME

    Simpsonized Me Hi, I'm Vikram Pant.

    On my site I share some ideas, solutions and other misc things I find online.

    During the day I work on various IT initiatives within the federal government. In my free time I enjoy reading up on, and testing out, new and emerging gadgets & technologies. (Read more)

    QUICK NOTE (E-MAIL)

    © 2009 Vikram Pant                 All Opinions Are My Own And Not That Of My Employer(s)