locked
wrong datetime RRS feed

  • Question

  • hi all,
    i've created new Entity which has DateTime attribute ,when i set the datetime for example 15/05/2009
    i noticed that datetime stored in database in cloumn name new_DateTime is 14/05/2009 not 15/05/2009 as i set in CRM

    any idea


    foreach(object HeartBeat in me.heart.Beats) messageBox.show("I miss u !!")
    Sunday, May 17, 2009 8:46 AM

Answers

  • In your last line, try replacing

     

     

     

    DateTime.Today.ToLongDateString() with DateTime.Today.ToUniversalTime().ToLongDateString()
    • Marked as answer by Dany85 Sunday, May 17, 2009 12:25 PM
    • Edited by Nimishas Sunday, May 17, 2009 12:26 PM
    Sunday, May 17, 2009 12:23 PM
  • Hi, Dany. Sorry for late responce. Wasn't near computer.

    1. Instaed of direct SQL Query use WebServices.
    2. If you use direct Selects to DataBase don't use such concatenations (there can be troubles with Sql Injections ). Use Parameters.
    3. If you use such query change it to:

                SqlCommand cmd = new
     SqlCommand();
                cmd.CommandText = @"SELECT [New_exceptioncustomerId]  FROM [MicrosoftCRM_MSCRM].[dbo].[New_exceptioncustomerExtensionBase] "
     +
                        "where [New_AgentId]= @AgentId and [New_CustomerNameId]= @CustomerNameId "
    +
                        " and [New_StartDate]= DateAdd(Hour, DateDiff(Hour, GetDate(), GetUtcDate()), @TodayDate)"
    ;
    
                cmd.Parameters.AddWithValue("@AgentId"
    , this
    .AgentProperty.Value);
                cmd.Parameters.AddWithValue("@CustomerNameId"
    , this
    .CustomerProperty.Value);
                cmd.Parameters.AddWithValue("@TodayDate"
    , DateTime.Today);
    
    

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Marked as answer by Dany85 Sunday, May 17, 2009 12:54 PM
    Sunday, May 17, 2009 12:42 PM
    Moderator

All replies

  • Is it still showing as 15/05/2009 in CRM??

    check the server's regional time/language settings and check your local CRM timezones settings.


    http://mscrmblog.net
    Microsoft Certified Business Management Solutions Specialist Microsoft Certified CRM Developer - sys admin
    Sunday, May 17, 2009 9:01 AM
  • i have opened CRM window in the server and setting datetime attribute through calendar and the datetime still deferent of database column  data, it always less than actual datetime one day
    foreach(object HeartBeat in me.heart.Beats) messageBox.show("I miss u !!")
    Sunday, May 17, 2009 9:12 AM
  • Hi, Dany.

    In CRM database date time fields are saved in UTC format. Value of date time smaller then your input on number of hour of your time zone number.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Sunday, May 17, 2009 9:42 AM
    Moderator
  • hi a33ik, how can i fix this issue and make the saved datetime like input datetime ?
    foreach(object HeartBeat in me.heart.Beats) messageBox.show("I miss u !!")
    Sunday, May 17, 2009 10:07 AM
  • Hi, Dany. It's not the error. Of course you can set in your personal settings that you are in first time zone. But it is incorrect.

    What goal do you want to reach?

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Sunday, May 17, 2009 10:11 AM
    Moderator
  • i have Entity named exception_contact, this entity has date time field named Startdate of exception
    i need to check this datetime every day in workflow check condition step and if that date time equals today then do somthing
    foreach(object HeartBeat in me.heart.Beats) messageBox.show("I miss u !!")
    Sunday, May 17, 2009 10:17 AM
  • Hi, Dany.

    There no need to change something. Workflow (if this not custom workflow which you wrote) will receive correct date time for check.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Sunday, May 17, 2009 10:20 AM
    Moderator
  • dear a33ik,
    it is custom workflow, so i need to check the datetime in my code
    foreach(object HeartBeat in me.heart.Beats) messageBox.show("I miss u !!")
    Sunday, May 17, 2009 10:23 AM
  • Dear Dany.

    I repeat that there no need to change something in Microsoft Dynamics CRM Options.

    Put here the code of thos date time retrieving, please. I will try to help you with your issue.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Sunday, May 17, 2009 10:26 AM
    Moderator
  • thank you a33ik i appreciate your help
    public static readonly DependencyProperty AgentPropertyProperty =
    
               DependencyProperty.Register("AgentProperty", typeof(Lookup), typeof(CustoemrException));
    
    
    
            [CrmInput("Agent")]
    
            [CrmReferenceTarget("new_agentid")]
    
            public Lookup AgentProperty
    
            {
    
                get { return (Lookup)GetValue(AgentPropertyProperty); }
    
                set { SetValue(AgentPropertyProperty, value); }
    
            }
    
    
    
            public static readonly DependencyProperty CustomerPropertyProperty =
    
                 DependencyProperty.Register("CustomerProperty", typeof(Lookup), typeof(CustoemrException));
    
    
    
            [CrmInput("Customer")]
    
            [CrmReferenceTarget("new_customernameid")]
    
            public Lookup CustomerProperty
    
            {
    
                get { return (Lookup)GetValue(CustomerPropertyProperty); }
    
                set { SetValue(CustomerPropertyProperty, value); }
    
            }
    
    
    
    
    
    string sqlQuery = @"SELECT [New_exceptioncustomerId]  FROM [MicrosoftCRM_MSCRM].[dbo].[New_exceptioncustomerExtensionBase] " +
    
                        "where [New_AgentId]='" + this.AgentProperty.Value + "' and [New_CustomerNameId]='" + this.CustomerProperty.Value +
    "' and [New_StartDate]='" + DateTime.Today.ToLongDateString() + "'";


    this query return no data because datetime is different in spite of  actual datetime 15/07/2009 which i set it   on the other hand database stored different datatime 14/07/2009
    foreach(object HeartBeat in me.heart.Beats) messageBox.show("I miss u !!")
    Sunday, May 17, 2009 10:34 AM
  • In your last line, try replacing

     

     

     

    DateTime.Today.ToLongDateString() with DateTime.Today.ToUniversalTime().ToLongDateString()
    • Marked as answer by Dany85 Sunday, May 17, 2009 12:25 PM
    • Edited by Nimishas Sunday, May 17, 2009 12:26 PM
    Sunday, May 17, 2009 12:23 PM
  • thanks, it is work good
    foreach(object HeartBeat in me.heart.Beats) messageBox.show("I miss u !!")
    Sunday, May 17, 2009 12:25 PM
  • Hi, Dany. Sorry for late responce. Wasn't near computer.

    1. Instaed of direct SQL Query use WebServices.
    2. If you use direct Selects to DataBase don't use such concatenations (there can be troubles with Sql Injections ). Use Parameters.
    3. If you use such query change it to:

                SqlCommand cmd = new
     SqlCommand();
                cmd.CommandText = @"SELECT [New_exceptioncustomerId]  FROM [MicrosoftCRM_MSCRM].[dbo].[New_exceptioncustomerExtensionBase] "
     +
                        "where [New_AgentId]= @AgentId and [New_CustomerNameId]= @CustomerNameId "
    +
                        " and [New_StartDate]= DateAdd(Hour, DateDiff(Hour, GetDate(), GetUtcDate()), @TodayDate)"
    ;
    
                cmd.Parameters.AddWithValue("@AgentId"
    , this
    .AgentProperty.Value);
                cmd.Parameters.AddWithValue("@CustomerNameId"
    , this
    .CustomerProperty.Value);
                cmd.Parameters.AddWithValue("@TodayDate"
    , DateTime.Today);
    
    

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Marked as answer by Dany85 Sunday, May 17, 2009 12:54 PM
    Sunday, May 17, 2009 12:42 PM
    Moderator
  • thanks a33ik, your response is very helpful
    i need your help in this thread http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/0ceed288-18a7-4fbe-8936-14de7e45e457
    foreach(object HeartBeat in me.heart.Beats) messageBox.show("I miss u !!")
    Sunday, May 17, 2009 12:54 PM