I have the following code:

if (filtro.FinalDate != null)
            {
                FinalDate = String.Format(" Data <= '{0}' ", filtro.FinalDate.GetValueOrDefault().ToString("yyyy-MM-dd") + " 23:59:59");
            }

But when I compile and type something in the FinalDate, the following message appears in the log:

Could not convert string to DateTime: 18/11/2014. Path 'FinalDate', line 1, position 102.

If FinalDate is a DateTime, you cannot assign a String to it as you do on line 3

The problem in your code is in the date part. Becuase there is no 18. month.
if you set a varialbe which tooks your date first, the problem will be solved.
Before doing this, first set your day month and year of your fitro object
The code below works.

        DateTime FinalDate=DateTime.Now;//your fitro object date will be here
        string xdate = String.Format(" Data <= '{0}' ", FinalDate.ToString("yyyy-MM-dd") + " 23:59:59");
        Text = xdate;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.