Best practice c# DateTime - Json



My model have a DateTime property i only need the date. On the couchbase server i see “2014-11-25T14:43:41.6738313+01:00” if it possible to save only the date?

Example: “2014-11-25” or date wit time “2014-11-25T14:43”

If i have 10 million items i think its need a lot of memory…



One solution i have found…

private string created; [JsonIgnore] public DateTime Created { get { return DateTime.ParseExact(this.created, "yyyyMMdd", CultureInfo.GetCultureInfo(1033)); } set { this.created = value.ToString("yyyyMMdd"); } }


Another option you might consider is saving the time as a long-Timestamp and not a DateTime in the first place. Your model would then have a method like GetDate() or GetDate() to get a readable Date. The Model/Json would only contain a long-Value.

But you need to consider if different TimeZones are relevant to you. The mentioned DateTime has “+01:00” in it, which marks it as a CET-Timestamp. That information gets lost if you only save the Date or the long-Value. Around 0:00 a different TimeZone can change the Date depending on your location.



The TimeZones are not relevant at the moment. But maybe i want use the dateToArray function and i thinks this function need a correct Format.