title: Best practice for storing DateTime values in Firebase with Unity3d
body: <p>I'm building a Unity3d 2D game where I'm using Firebase as the database. I need to store quite a lot of <code>DateTime</code> values (as UTC) in the database and I'm wondering what the best practice is for doing this.</p>
  
  <p>The <code>DateTime</code> fields will mainly be used for sorting/filtering.</p>
  
  <p>According to the Firebase documentation, I should make use of the <code>Firebase.Database.ServerValues.TIMESTAMP</code> which is just an <code>object</code></p>
  
  <p>Thing is, I'm using strongly typed models for my Unity game, like so:</p>
  
  <pre><code>[Serializable]
  public class Profile {
  
      [NonSerialized]
      public string ProfileKey;
  
      // Serializable attributes
      public string userId;
      public string name;
      public int age;
      public string gender; // "M" or "F"
      public DateTime utcCreated; // UTC   
      public DateTime utcUpdated; // UTC
  }   
  </code></pre>
  
  <p>and when I save/update a <code>Profile</code> I'm using Unitys <code>JsonUtility.ToJson()</code> method, like this:</p>
  
  <pre><code>var profiles = db.Child ("profiles");
  
  Profile profile = new Profile {
      userId = GameManager.Instance.User.UserId,
      name = "My new profile",
      age = 23,
      gender = "M",
      utcCreated = ?? // Should somehow use Firebase.Database.ServerValues.TIMESTAMP here, I guess?
  };              
  
  string json = JsonUtility.ToJson (profile);     
  
  var profileKey = profiles.Push ().Key;
  
  profiles.Child (profileKey).SetRawJsonValueAsync (json, 1).ContinueWith (t =&gt; {
      // .. handle response here
  });
  </code></pre>
  
  <p>I'm not sure what exactly I should set the <code>utcCreated</code> field to on my model. Tried to simply make the field an <code>object</code>, but no value was inserted into Firebase. Also tried to make it a string with a <code>.ToString()</code> to the <code>Firebase.Database.ServerValues.TIMESTAMP</code>object, but no value was inserted in Firebase.</p>
  
  <p>Does anyone have an idea how to do this? ;-) Or just any help/hint on best practices for storing dates and timestamps in Firebase?</p>
  
  <p>Thanks in advance.</p>