Saved DateTime field value 1h diff

Hi!

When saving a Datetime property value and then fetching it there is a diff of one hour. Why? Does the current cultureInfo interfere somehow? This is how we save the value:

            var _personService = IoC.Resolve<PersonService>();
            var personClone = person.MakeWritableClone();
            personClone.Fields.AddOrUpdateValue("datetimeproperty", DateTime.Now); // e.g. 2020-02-25 14:00

            using (Solution.Instance.SystemToken.Use())
            {
                _personService.Update(personClone);
            }

And this is how we fetch the value:

var date = currentPerson.Fields.GetValue<DateTime>("datetimeproperty"); // date = 2020-02-25 13:00

Litium version: 7.2.3

I believe internally the date is converted to universal time, so if you saved with DateTime.UtcNow instead it would match.

The date-time field type is using DateTimeOffset as the datatype and the value is converted to UTC, that’s the reason that you are getting the UTC version of your time back when you fetch that.

If you instead use var date = currentPerson.Fields.GetValue<DateTimeOffset>("datetimeproperty"); you should get the correct value out with the correct time zone.

Ok, that explains it. Thanks @NilsN, @patric.forsgard

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.