Search code examples
c#datetimeebay-api

Format DateTime without converting it to String


I have a GetOrders class that required me to supply the start and end dates as the DateTime values. Nevertheless, when I supply the dates, I am getting this error message: Sorry, the end date was missing, invalid, or before the start date. <EndDate> must be in YYYY-MM-DD or YYYY-MM-DD HH:MI:SS format, and after the start date.

This is my code:

ff.GetOrders(DateTime.UtcNow, DateTime.UtcNow.AddMonths(-1), TradingRoleCodeType.Buyer, OrderStatusCodeType.Completed);

When I try to use formatted string, it does not work:

        String dt1 = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
        String dt2 = DateTime.UtcNow.AddMonths(-1).ToString("yyyy-MM-ddTHH:mm:ssZ");

Solution

  • Assuming GetOrders has startdate,enddate (which I can't tell because you didn't give the function prototype for GetOrders), then your dates are in the wrong order or you should AddMonths(1) instead of -1.

    (If this isn't the case, please include the function proto for GetOrders and I will revise or delete my answer.)