I Have a list (Orders list) where i have a column "CreationDate" as internal name.

That column stores datetime of the order.

When I show this column in a View, it appears in the format "dd/mm/yyyy" and that is good for me.

The problem comes when I need to do it:

myItens = (from SPListItem item in list.Items
                           where (Convert.ToDateTime(item["DateCreation"]).ToShortDateString() == Convert.ToDateTime("12/14/2012").ToShortDateString() ) && // Convert.ToDateTime("14/12/2012").ToShortDateString()) &&
                                   (item["Statut"].ToString() == "En cours de traitement") &&
                                   (item["TypeLigne"].ToString() == tLigne)
                           select item).ToList();

... for the Convert.ToDateTime("12/14/2012").ToShortDateString() it answer me for this format: "12/14/2012"... if i use the correct (14/12/2012) format it doesnt work!!

I receive a error message like the date is not in correct format.

Someone can help?

Thnk you.

1 Answer 1


Taken from the Convert.ToDateTime method description on the MSDN.

If value is not null, the return value is the result of invoking the DateTime.Parse method on value using the formatting information in a DateTimeFormatInfo object that is initialized for the current culture

You said "if I use the correct 14/12/2012": if your server locale is English, then it's not the correct format, and that's why 12/14/2012 is parsed correctly. If you need to parse a date with a specific format, you should use the DateTime.ParseExact(value, format, CultureInfo.CurrentCulture) method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.