none
Active Directory, Format of date/time properties in C# RRS feed

  • Question

  • Hello Mate,

    I am trying to make a decision at AD Management Agent Sync based on the value of Whencreated attribute in AD on daily basis.

    When I import the value whencreated in AD connector space, the value is 20141209193924.0Z

    I was believing it follow the format

    YYYY -> four digit year
    MM -> 2 digit month
    DD -> 2 digit day

    The code                   

    if (csentry["Whencreated"].IsPresent)

                            {
                               DateTime currentDateTime = DateTime.Now;
                               String dateStr = currentDateTime.ToString("yyyyMMdd");
                               if (csentry["Whencreated"].Value.Remove(8).Equals(dateStr))

                                {

                                  // Do Something.

                                }

                            }

    However if I look whencreated attribute for the user in AD it is 12/10/2014 1:09:24 AM and see there is a difference of 1 day.
    Kindly help how to convert the value of the format 20141209193924.0Z to date and time in C#

    Thanks and Regards,
    Anirban Singha

     

    Wednesday, December 10, 2014 6:16 PM

Answers

  • Hi All,

    The below is the way it works.

    case "CreatedinAD" :

                           string format = "yyyyMMddHHmmss.0Z";

     DateTime whenCreated = DateTime.ParseExact(csentry["whenCreated"].StringValue, format, System.Globalization.CultureInfo.InvariantCulture);

                            string ti = whenCreated.ToString("MM/d/yyyy");

                            DateTime nt = Convert.ToDateTime(ti);             

                       

                       

                        if ((nt- DateTime.Today).TotalDays == 0)

                        {

                            //  logic goes in this block.

                        }

                            break;

    Regards,

    Anirban Singha

    • Marked as answer by AnirbanSingha Saturday, January 3, 2015 10:27 PM
    Saturday, January 3, 2015 8:27 PM

All replies

  • Hi,

    Verify if the System time and Time Zone of the AD Domain controllers, Database and FIM servers are same.

    Thanks,

    Venkatesh

    Monday, December 15, 2014 10:26 AM
  • Hi All,

    The below is the way it works.

    case "CreatedinAD" :

                           string format = "yyyyMMddHHmmss.0Z";

     DateTime whenCreated = DateTime.ParseExact(csentry["whenCreated"].StringValue, format, System.Globalization.CultureInfo.InvariantCulture);

                            string ti = whenCreated.ToString("MM/d/yyyy");

                            DateTime nt = Convert.ToDateTime(ti);             

                       

                       

                        if ((nt- DateTime.Today).TotalDays == 0)

                        {

                            //  logic goes in this block.

                        }

                            break;

    Regards,

    Anirban Singha

    • Marked as answer by AnirbanSingha Saturday, January 3, 2015 10:27 PM
    Saturday, January 3, 2015 8:27 PM
  • If you configure sync rules to FIM Portal, you can use following customExpression at inbound flow:

    Left(whenCreated,4)+"-"+Mid(whenCreated,5,2)+"-"+Mid(whenCreated,7,2)+"T"+Mid(whenCreated,9,2)+":"+Mid(whenCreated,11,2)+":00.000"

    /Juho

    Wednesday, February 4, 2015 11:39 AM
  • void IMASynchronization.MapAttributesForImport( string FlowRuleName, CSEntry csentry, MVEntry mventry)
            {
                //
                // TODO: write your import attribute flow code
                //
                switch (FlowRuleName)
                         {

                               case "wcreated":

                        string format = "yyyyMMddHHmmss.0Z";
                        DateTime whenCreated = DateTime.ParseExact(csentry["whenCreated"].StringValue, format, System.Globalization.CultureInfo.InvariantCulture);

                        string time = whenCreated.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.000'");

                      //  DateTime newtime = Convert.ToDateTime(time);
                        mventry["created"].Value = time.ToString();
                        break;

                    default:
                        // TODO: remove the following statement and add your default script here
                        break;
                }
            }

    • Proposed as answer by Shashidhar J Monday, March 12, 2018 9:50 AM
    Monday, March 12, 2018 9:50 AM