locked
converting timespan to datetime RRS feed

  • Question

  • Hi

    I want to set a DateTime column in Sharepoint to the difference of 2 other DateTime Columns.

    DateTime var1 = Convert.ToDateTime(workflowProperties.Item["TS_Complete"]);
    DateTime var2 = Convert.ToDateTime(workflowProperties.Item["TS_Start"]);
    
    
    System.TimeSpan diff1 = var1.Subtract(var2);
    workflowProperties.Item["Duration"] = diff1;
    It only works if Duration is a String Format column not a DateTime, How Can i convert to DateTime ?
    Monday, June 25, 2012 11:12 AM

Answers

  • Remember the DateTime is supposed to store dates, not time spans. There is no such thing as a TimeSpan field in SharePoint OOTB, so why not using a String to store the value? If you think about it, storing the difference as a DateTime makes little sense.

    Alex Ferreira :: Blog: http://sharepointsofview.blogspot.com/ :: Twitter: @alexaem


    Monday, June 25, 2012 1:14 PM

All replies

  • Many post available under this same forum

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/20304b8c-1e2d-4130-86ba-6c30f5ee6175

    http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/bf1f6f81-efb4-4bb4-be3b-9f88a006b903


    Regards, Dharnendra Shah, MCTS,MCPD - Sharepoint 2010 Application Development Blog: http://ds-sharepoint2010blogs.blogspot.in/ Email: shahdg2003@gmail.com

    Monday, June 25, 2012 11:14 AM
  • Did you try convert the datetime to ISO standard?

    Convert from DateTime to ISO8601 DateTime (C#):
    DateTime date = DateTime.Now;
    string isoDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(date);

    Monday, June 25, 2012 11:43 AM
  • Remember the DateTime is supposed to store dates, not time spans. There is no such thing as a TimeSpan field in SharePoint OOTB, so why not using a String to store the value? If you think about it, storing the difference as a DateTime makes little sense.

    Alex Ferreira :: Blog: http://sharepointsofview.blogspot.com/ :: Twitter: @alexaem


    Monday, June 25, 2012 1:14 PM
  • Agreed Alex ;)

    thanks, I was coming to the came conclusion

    Monday, June 25, 2012 1:31 PM