I am working on a method to query an existing table with one of the columns to be datetimeoffset "2021-02-06 05:00:00.0000000 -04:00"
I have a stored procedure that accepts the startDate and endDate. I want the startDate to be the beginning of the day(startDate) and the end of the day(endDate)
var DateToStartOfDay = StartDate + " 00:00:01.0000000 -04:00";
var DateToEndOfDay = EndDate + " 23:59:00.0000000 -04:00";
//DateTimeOffset.Parse
var startDate = DateTimeOffset.Parse(DateToStartOfDay);
var endDate = DateTimeOffset.Parse(DateToEndOfDay).AddDays(1);
The above code works perfectly on my system but one I deploy to Azure App Service, I got this error
String '2018-02-29 23:59:00.0000000 -04:00' was not recognized as a valid DateTime."
I suggest you can set string
type in StartDate
.
My test code
public string bb(string aa) {
try
{
var DateToStartOfDay = aa + " 00:00:01.0000000 -04:00";
var startDate = DateTimeOffset.Parse(DateToStartOfDay);
return startDate.ToString();
}
catch (Exception ex)
{
return ex.ToString();
throw;
}
}
Test Result
Although the Azure web app runs in the sandbox environment, we can use it as a cloud server. The local effect should be the same as that deployed in the azure web app. If there is still NULL, it is recommended to add try... catch... to catch the exception. Or learn how to remote debug .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.