HomeDevelopment (Old) SPException invalid date/time (Erreur : Valeur de date/d’heure non valide. Un...

[SharePoint 2010 – Error Fixing] SPException invalid date/time (Erreur : Valeur de date/d’heure non valide. Un champ de date/d’heure contient des données non valides. Vérifiez la valeur, puis réessayez)

What did i try to do ?

I’m creating SPListItem Programmatically (create elements in a list) and when the item.update(); is called by the code, the following error is thrown :
“Erreur : Valeur de date/d’heure non valide.Un champ de date/d’heure contient des données non valides. Vérifiez la valeur, puis réessayez”
or in english :
“SPException : invalid date/time…”

What could be the problem ?

  1. The date format is not correct
  2. The date is not correct (minimum date for SharePoint ?)

Solving the problem

I’m giving an example of an incorrect date value “01/01/0001 00:00:00” :

   1: SPList list = web.Lists["myList"];
   2:  
   3: SPListItem item;
   4: string date = "01/01/0001 00:00:00";
   5:  
   6: item = list.Items.Add();
   7:  
   8: item["currentDate"] = date;
   9: if (DateTime.TryParse(row["currentDate"].ToString(), out dateTime) == true)
  10: {
  11:     //si la date est définit
  12:     if (dateTime.ToString() != "01/01/0001 00:00:00")
  13:     {
  14:         item["currentDate"] = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Parse(date));
  15:     }
  16: }
  17:  
  18: item.update();
  19: list.update();

01/01/2001 is an incorrect value for a date in sharepoint.

And we check the date in order to respect sharepoint dates rules, using the method : CreateISO8601DateTimeFromSystemDateTime.

Have you ever had other issue with dates and SPListItem ?

- Advertisement -

1 COMMENT

  1. [* WordPress Security Firewall plugin marked this comment as “trash”. Reason: Failed GASP Bot Filter Test (checkbox) *]
    I visit daily some web pages and sites to read articles,
    but this blog provides quality based writing.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

CONNECT FOR MORE CONTENT

DO NOT MISS THOSE ARTICLES

Recent Comments