function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kosmitevkosmitev 

DateTime comparison which ignores the milliseconds part

Hi There,

I have an interesting prolem.

1. I create a new Accounts' view and for condition I set:

    DateTimeFieldX equals 31/01/2012 15:45

    I save the view and it returns me a record with the DateTimeFieldX equaling: 2012-01-31T15:45:03.000Z.

    From that I can see that it is ignoring the :03 milliseconds part.

 

2. I open the Force.com Explorer and I type in the following query:

    SELECT  Name FROM Account where DateTimeFieldX = 2012-01-31T15:45:00Z and I get nothing which is understandable

     because I have 00 for milliseconds.

 

The question is how to the where clause condition in 2 above to ignore the milliesconds value and to return me whatever 1 above returns.

To put this into perspective I am building a where clause in .Net which is similar to SF's and I let users enter date and time up-to the millisecond.

 

For those of you who are looking for a solution on how to cnovert DateTime to a DateTime field suitable for SOQL query in .Net here it is:
 public string Convert(DateTime obj, Field field = null)
 {
     return System.Xml.XmlConvert.ToString(obj, System.Xml.XmlDateTimeSerializationMode.Utc);
  }

 

Thanks,

Kos

Best Answer chosen by Admin (Salesforce Developers) 
Richie DRichie D

Hi Kosmitev,

 

You may need to check the time part as the 03 is the seconds part and NOT the milliseconds.

 

You could create a SOQL expressions like:- 

 

Select a.CreatedDate From Account a where createddate >= 2012-01-09T08:55:00.000Z and createdDate < 2012-01-09T08:56:00.000Z

 to ignore which ever amount of time you are not interested in. In this case we only want records that were added in the 08:55th minute on 2012-01-09.

 

Does this help?

 

Rich.

All Answers

Richie DRichie D

Hi Kosmitev,

 

You may need to check the time part as the 03 is the seconds part and NOT the milliseconds.

 

You could create a SOQL expressions like:- 

 

Select a.CreatedDate From Account a where createddate >= 2012-01-09T08:55:00.000Z and createdDate < 2012-01-09T08:56:00.000Z

 to ignore which ever amount of time you are not interested in. In this case we only want records that were added in the 08:55th minute on 2012-01-09.

 

Does this help?

 

Rich.

This was selected as the best answer
kosmitevkosmitev

Richie,

Thank you for responding.

I am curious as to whether that is that how SF does it as well?

Anyway your solution seems valid and I will mark it as an answer.

 

Regards,

Kos

kosmitevkosmitev

By the way your link in your signature does not work.