locked
Storing DateTime to Table Storage - once UTC another time local RRS feed

  • Question

  • Weird stuff... Look at this TableEntity initialization:

    			Patient patient = new Patient
    			{
    				DateOfBirth = new DateTime(2009, 5, 15),
    				//DateOfBirth = DateTime.Today,
    				FirstName = "Alex",
    				LastName = "Bee",
    				Title = "Mr."
    			};
    
    If I store this entity with DateTime(2009, 5, 15) to Table storage (using Storage Emulator) and then read it back the retrieved value is exactly the same. Now, if I uncomment the line with DateTime.Today the value I get is UTC (which is in my case 4 hours difference)! So, ... WTF? :) What am I missing here?

    Thursday, April 9, 2015 3:08 PM

Answers

All replies

  • I guess I got it - the workaround is to ALWAYS convert datetime value to Utc time and back (in getter and setter).
    Thursday, April 9, 2015 3:12 PM
  • Hi

    That's true, for date times, we should always use UTC specially if there is load balancer involved or you are hosting the services in the cloud where you dont know which time zone the server will have..

    So as a general practice use UTC dates all the time.

    Regards

    Aram

    Friday, April 10, 2015 4:33 AM
  • Azure stores date as UTC date so it's upto the developer to store the correct datetime considering UTC datetime.

    Tuesday, April 14, 2015 5:03 PM