Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I am trying to retrieve users from AD by querying using Hired date which is whenCreated property.
I enter the date in the search box which is text box in MM/DD/YYYY format (I have tried almost all the formatts.)

When I search by the First name or Display name I get the results but this property is not returning any value.

What I have tried:

query I am passing : dirSearch.Filter = "(whenCreated=*" +dtnew.ToString("yyyyMMddHHmmss.s")+ "*)";
I am using stars so that it will return even the field contains the value I am passing. dtnew is a datetime variable used like below.
DateTime dtnew = DateTime.Now;
string newDate = "10/28/2014 3:21:41 PM";
dtnew = Convert.ToDateTime(newDate);
dirSearch.Filter = "(whenCreated=*" +dtnew.ToString("yyyyMMddHHmmss.s")+ "*)";

queried I have tried : dirSearch.Filter = "(whenCreated=*"+ userName +*)";
userName is the string that get value from the text search box.

I have tried giving the hard coded value too.
Posted
Updated 11-Oct-17 6:53am
v2
Comments
Karthik_Mahalingam 11-Oct-17 23:32pm    
check this https://msdn.microsoft.com/en-us/library/system.directoryservices.directorysearcher.filter(v=vs.110).aspx


When the filter contains an attribute of ADS_UTC_TIME type, its value must be of the yyyymmddhhmmssZ format where y, m, d, h, m, and s stand for year, month, day, hour, minute, and second, respectively. The seconds (ss) value is optional. The final letter Z means there is no time differential. In this format, "10:20:00 A.M. May 13, 1999" becomes "19990513102000Z". Note that Active Directory Domain Services stores date and time as Coordinated Universal Time (Greenwich Mean Time). If you specify a time with no time differential, you are specifying the time in GMT time.
Bevin wc 12-Oct-17 5:52am    
Karthik - It is not working. I have a record for which the Hire date is 8/3/2016 5:32:03 PM. SO i have tried 20160803173203Z and also 20160803173203.0+5300 (5300 for India) and 20160803173203.0Z. But none of these queries returning me the result which I get normally .
Richard Deeming 12-Oct-17 13:57pm    
Is that 5:23 PM in UTC, or in your local time-zone?

India should be 0530, not 5300. And I'm not convinced by the ".0", even though it's in the documentation.

Try one of:
20160803173203+0530
20160803173203.0+0530
20160803120203Z

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900