Adding Time to DateTime Fields in SharePoint Lists

Recently a fellow list member ran into a snag while trying to create a calculated field of the form [DateTimeField1 + TimeValue].  Ostensibly, his problem was the lack of seconds in the displayed value; in reality, however, the initial approach betrayed an all-too-common misunderstanding of the way date and time values are treated in SharePoint.

The heart of the problem turned out to be the TIME function.  This takes a set of three integer parameters (hours, minutes, seconds) and converts them into a decimal value as a fraction of a day.  For example, the conversion of 10:20:15, or TIME(10, 20, 15) would yield a return value of 0.43.  This can't actually be added to a datetime field unless you convert the field value with the same function, which leaves you with just the sum of the times (and not in a very usable format).

The alternative, then, is the somewhat more intuitive (if more obscure) method of simply adding the two datetime/time fields, like this:

 =[DateTimeField1] + TimeValue

For the final piece, the field needs to be displayed in the desired format, which in this case includes the display of seconds.  The TEXT function -- which converts a given value type to a string based on the provided formatting expression -- will do the job.

 =TEXT(([DateTimeField1] + TimeValue), "m/d/yyyy h:MM:ss")

This formatting should be familiar to anyone who has worked with date and time data in Microsoft development tools, whether VBA in Office or C# in ASP.NET.

Obviously the string can be altered to include only date, only time, or a longer date format; this should serve as a starting point for whatever time calculations you might need.

6 Comments

  • Hello...

    I am using Room & equipment reservation template. To reserve a room i have start date and end date. what i need is...

    Start date : Should be equals to or greater than today's date & time. system should not allow any reservation done less then today's date & time.

    how can i do that.

    any help will be highly appreciated.

    Thank you

  • My =TEXT(([DateTimeField1] + TimeValue), "m/d/yyyy h:MM:ss")

    is

    =TEXT(([GMT Time] - 05:00:00), "m/d/yyyy h:MM:ss") for Eastern GMT - 5 hours

    GMT Time is my column with the date 1/24/2010 06:00

    I get bad formula errors. Any advice is appreciated.

    Thanks!

  • I am trying to add a military DTG (031339ZMAY10) to the "calculated value" field of a new column. I've tried several combinations with no success. Any help would be much appreciated.

    V/R
    John

  • How can I get it to display the Monday of the current week? I have several people adding items and I want to be able to sort them by date (Monday of the week). Thanks!!

  • Hi,
    I need to add three working days and display as default date. I did it putting =Today+3 in the calucated value fied. But I want to add 3 working days and exclude saturday and sunday. How can I do this

  • Bonus question: now that you have a calculated column that is date/time – can you create a “Calendar” view using it?
    (I keep getting “Unexpected error” on view create – (even though resulting column values are type “date & time” and have normal values…)

Comments have been disabled for this content.