One of our procedures lets users bulk-insert related records by picking a view and then hitting a ribbon button. The form is saved, a flag is set, and a plugin then does its
When working with dates, always remember to convert to utc since that is how CRM stores them in the database.
The native CRM Advanced find is going to look at whatever the current user's time zone is, and convert that whatever time they enter into the advanced find to UTC before performing a SQL query. Your plugin control will need to do the same thing. These are the steps you'll need to perform before putting the criteria in the Fetch Xml / Linq Expression / Query Expression.
public static DateTime ConvertTimeToUTC(DateTime time, TimeZoneInfo timeZone)
{
if (time.Kind != DateTimeKind.Unspecified)
{
// If the DateTime is created with a specific time zone(ie DateTime.Now), getting the offset will
// blow chow if it isn't the correct time zone:
// The UTC Offset of the local dateTime parameter does not match the offset argument.
//Parameter name: offset
// This quick check will recreate the serverLocal time as unspecified
time = new DateTime(
time.Year,
time.Month,
time.Day,
time.Hour,
time.Minute,
time.Second,
time.Millisecond);
}
var offest = new DateTimeOffset(time, timeZone.GetUtcOffset(time));
return offest.UtcDateTime;
}