Hi All,
I have updated title with one of date time field value in crm through console.This date field is user local behaviour & format is date only.
But when its updating its showing 1 day less for ex : date reported field has : 20/07/2021 but in title it updated with 19/07/2021.
Below code i have tried with taking adding 1 day also but dont think in this way it will work as it depends on time zone.
foreach (var enitem in completeCaseCollection)
{
var title = enitem.Attributes.Contains("title") ? enitem.GetAttributeValue<string>("title") : string.Empty;
var dateReported = enitem.Contains("new_datereported") ? enitem.GetAttributeValue<DateTime?>("new_datereported") : new DateTime();
string day = dateReported.Value.AddDays(1).Day.ToString("00");
string month = dateReported.Value.Month.ToString("00");
int year = dateReported.Value.Year;
string updatedDate = $"{day}{month}{year}";
int pos_RunningCounter = title.LastIndexOf("-") + 1;
string InteractionType = title.Substring(0, title.IndexOf("-"));
string RunningCounter = title.Substring(pos_RunningCounter, title.Length - pos_RunningCounter);
string updatedTitle = $"{InteractionType}-{updatedDate}-{RunningCounter}";
// Stage Status Update
Entity caseUpdate = new Entity("incident");
caseUpdate["title"] = updatedTitle;
if (enitem.Id != null)
caseUpdate.Id = enitem.Id;
if (Service != null)
Service.Update(caseUpdate);
}
What could be the solution instead modifying behaviour to time zone independent. Is there any other way to do from code side to convert time ?
Thanks,
Jharana