CRM dates one day too early when accessing them via LINQ

For one of my a clients I had to make something to import records from their old invoicing system into the new CRM via csv files. When this was completed it had to export result data they would use to check if all the data was transferred correctly. Because they had to "practice" this import many times I decided to make a Windows Forms application and access the CRM data via the API using LINQ.

In the exported data I noticed that date fields came out one day too early. For example in the CRM interface the date was shown as 6/25/2015 but in my export files the dates showed up as 6/24/2015 which looked like very strange behavior to me.

After some investigation I noticed that date time fields in CRM are saved in the database as CET time. The project location was the Netherlands so the time difference with CET was 2 hours. When you have a CRM date only field it will send the time part along as 00:00:00 so when I entered 6/25/2015 in CRM it turned up as 6/24/2015 22:00:00 in the database.

So this way, when selecting date/time values via LINQ you come up one day short. This can be a nasty little problem that may cost you a lot of time to figure out.

Anyway, the solution for this problem is rather simple. Just convert the date time field ToLocalTime()

var contact = (from c in ContactSet
               where c.FullName == "Edwin Hebbink"
               select c).FirstOrDefault();
 
Console.Write(contact.BirthDate);
Console.Write(Convert.ToDateTime(contact.BirthDate).ToLocalTime());

Just replace the "Edwin Hebbink" part with some contact name you have in your CRM and run this piece of code in LINQPad for CRM as a C# Statement and you will get the following result:


As you can see the first date is one day earlier then the second one.

If you want to read some more about CRM date/time issues this would be a very interesting article. In that article they talk about CRM 2011 but all this stuff still applies to the later versions as well.

Comments (5) -

  • article writing service

    1/4/2017 9:41:07 AM |

    I really want to get through the problems that I have with my laptop.

  • http://essaywriter-s.com/about.php

    1/28/2017 3:44:00 PM |

    That's great. I would like to get here more details on the topic. I think that some of those materials should be important for the understanding of the whole thing.

  • proofreading editing services

    2/8/2017 7:17:01 PM |

    Yes, I have this sort of a problem since. It was highly complicated for me. So, I've asked for a help.

  • BWVlndv

    4/19/2017 4:22:11 AM |

    380066 362257I liked than you may be right now. 626837

  • trenadex acetate 100

    5/19/2017 11:49:13 AM |

    693587 304257Deference to op , some  superb   entropy. 169133

  • personalised workwear clothing

    5/20/2017 2:17:34 PM |

    174733 678378I really    glad  to locate this  web site on bing, just what I was searching  for : D  as properly  saved to favorites . 880021

  • motor club of america training

    5/22/2017 5:16:35 AM |

    297235 429321An intriguing discussion is worth comment. I do feel which you really should write read far more about this subject, it will not be considered a taboo topic but normally every person is too couple of to communicate in on such topics. To one more. Cheers 744338

  • serrurier agréé assurance

    5/24/2017 2:58:05 PM |

    212087 553339dog grooming is the specialty of my sister, she really loves grooming every dog in our house   852067

  • friv.press

    5/24/2017 3:26:11 PM |

    469411 145496Its  superb  as your other posts  : D,  regards  for posting . 332086

  • Emobility

    5/27/2017 10:21:20 PM |

    863505 574999My wife style of bogus body art were being quite unsafe. Mother worked with gun initial, following which they your lover snuck totally free upon an tattoo ink ink. I was certain the fact just about every ought to not be  epidermal, due to the tattoo ink could be attracted from the entire body. make an own temporary tattoo 578030

  • georgia

    5/30/2017 9:39:34 AM |

    45423 320996Fairly uncommon. Is likely to appreciate it for men and women who incorporate community forums or anything, internet internet site theme . a tones way for the client to communicate. Exceptional job.. 131270

  • 741846 940784Hey I was just searching at your web site in Firefox and the image at the top with the link cant show up properly. Just thought I would let you know. 161521

  • SIMAD UNIVERSITY

    5/31/2017 1:17:59 PM |

    239522 952436You�ve created various good points there. I did specific search terms about the matter and located mainly individuals will believe your web site 448258

  • Family

    6/4/2017 5:05:56 PM |

    505432 716673This sort of wanting to come to a difference in her or his lifestyle, initial usually Los angeles Excess weight weightloss scheme is really a large running in as it reached that strive. weight loss 631505

  • 956283 938571Hmm is anyone else encountering problems with the pictures on this blog loading? I�m trying to figure out if its a problem on my end or if it�s the blog. Any responses would be greatly appreciated. 940285

  • cara pendaftaran cpns

    7/14/2017 3:04:06 PM |

    137167 223546I  as effectively  believe   thence , perfectly  pent  post! . 127900

  • GVK Biosciences

    7/14/2017 3:15:29 PM |

    763328 474585Hosting a blog composing facility (in a broad sense) requires unlimited space. So I suggest you to discover such web hosting (internet space provider) that offer flexibility inside your internet space. 989659

  • mtn

    7/18/2017 10:56:26 PM |

    156476 197595So, is this just for men, just for women, or is it for both sexes If it s not, then do women require to do anything different to put on muscle 943005

  • La Liga Predictions

    7/20/2017 7:42:12 PM |

    613329 821173The subsequent time I read a weblog, I hope that it doesnt disappoint me as a great deal as this 1. I mean, I know it was my option to read, but I truly thought youd have something attention-grabbing to say. All I hear is actually a bunch of whining about something which you possibly can repair need to you werent too busy on the lookout for attention. 766437

  • get seedbox

    7/21/2017 2:59:59 PM |

    769950 432250hey was just seeing if you minded a comment. i like your site and the theme you picked is super. I will be back. 160353

  • TS TV Escorts from London

    7/28/2017 3:38:49 PM |

    571583 707393There exist a couple of a lot of different distinct levels among the California Weight loss program and each and every a person is pretty crucial. You are procedure stands out as the the actual giving up with all the power. weight loss 809722

  • מיזוג אוויר

    8/17/2017 2:35:36 AM |

    296854 273944I  real   glad  to find this  web website  on bing, just what I was  searching  for : D  likewise   saved to bookmarks . 18733

  • gambar pemandangan

    8/28/2017 10:40:02 PM |

    410196 28483I like this  internet blog  very a lot so a lot  superb  info  . 189484

  • roofing

    8/30/2017 1:58:34 PM |

    482524 792997This really is such an excellent post, and was thinking significantly exactly the same myself.  An additional great update. 634703

  • gvk biosciences

    9/6/2017 10:50:42 AM |

    844019 203425Lastly, got what I was seeking for!! I�ve actually enjoying every small bit of this. Ecstatic I stumbled into this post! and also I�ve bookmarked to look at unique data for your weblog post. 361702

  • Sistem Klinik

    9/15/2017 3:29:20 AM |

    131347 374190An fascinating dialogue is value comment. I feel that it�s greatest to write extra on this matter, it might not be a taboo topic even so generally people are not enough to speak on such topics. To the next. Cheers 775709

Loading