locked
createTimeStamp format RRS feed

  • Question

  • User-1964924944 posted

    I am importing user information into a web system I just created from LDAP.  I am matching up all the variables with the attributes and I came across createTimeStamp attritubute.  It is formatted like so:  20090903103550.0Z

    The .0Z at the end is for time zone, I've figured that out.  However, I'm not sure how to convert it in ASP.net and format it for datetime in MSSQL.

    Any ideas on how to convert the string?

    Tuesday, September 8, 2009 1:24 PM

Answers

  • User-2009597737 posted

    The AD date is stored as "Ticks" from 1/1/1600 if I am not wrong. Something like this should convert the ticks to date-time: this is c#


         string  Dt2Ticks(string inputDate)
            {
                DateTime dt;
                long dt2ticks, startTicks;
                string d;

                startTicks = new DateTime(1601, 01, 01, 00, 00, 00, new CultureInfo("en-US", false).Calendar).Ticks;

                d=inputDate + " 01:01:01 AM";
                dt=Convert.ToDateTime(d);                        // string 2 date ...
                dt2ticks=dt.Ticks - startTicks;                    // Date 2 ticks ...
                return dt2ticks.ToString();
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 9, 2009 2:29 PM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2009 12:34 AM

All replies

  • User-1964924944 posted

    Anyone at all on this?

    Wednesday, September 9, 2009 10:13 AM
  • User-2009597737 posted

    The AD date is stored as "Ticks" from 1/1/1600 if I am not wrong. Something like this should convert the ticks to date-time: this is c#


         string  Dt2Ticks(string inputDate)
            {
                DateTime dt;
                long dt2ticks, startTicks;
                string d;

                startTicks = new DateTime(1601, 01, 01, 00, 00, 00, new CultureInfo("en-US", false).Calendar).Ticks;

                d=inputDate + " 01:01:01 AM";
                dt=Convert.ToDateTime(d);                        // string 2 date ...
                dt2ticks=dt.Ticks - startTicks;                    // Date 2 ticks ...
                return dt2ticks.ToString();
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 9, 2009 2:29 PM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2009 12:34 AM