I'm working on a ASP.NET application which is calling our salesforce org via REST API. There is a feature to search data based on time period(DateTime
field) as follows.
- Today
- Yesterday
- Last 7 days
- Custom selection (this is where I'm struggling)
Previously all filters were implemented by creating appropriate DateTime
instance in .NET
end and passing it to the query string. But the Time Zone difference is impacting the search results which I can understand.
Then first three filter criteria were implemented with SOQL Date Literals and looks working fine. But for the last option I should take user input and create the fromDate
and toDate
in C#
, then pass into my query string.
"?q=SELECT my_fields FROM my_Object__c WHERE Date_Registered__c > " + DateTime.Parse(txtFromDate.Text.Substring(6, 4) + "/" + txtFromDate.Text.Substring(3, 2) + "/" + txtFromDate.Text.Substring(0, 2)).ToString("yyyy-MM-ddTHH:mm:ss.000Z") + " and Date_Registered__c < " + DateTime.Parse(txtToDate.Text.Substring(6, 4) + "/" + txtToDate.Text.Substring(3, 2) + "/" + txtToDate.Text.Substring(0, 2)).AddDays(1).ToString("yyyy-MM-ddTHH:mm:ss.000Z");
In this way I can't handle the time zone impact on my search results. So it's giving some unexpected results. There are so many examples to handle these when using Apex
. But here it's for .NET
and I found nothing useful.
Any guidance appreciate.
Thanks
convertTimezone
here if there is a way. But still no luck. Can't think of a way to handleDAY_IN_MONTH(convertTimeZone(Date_Registered__c)) >25 and DAY_IN_MONTH(convertTimeZone(Date_Registered__c)) < 02
like scenario when thefromDate
andtoDate
are from different calendar months. I tried applyingCALENDAR_MONTH()
,CALENDAR_YEAR()
,DAY_IN_MONTH()
altogether.