Time manipulation using SQL SP or C#

Posted on 2011-05-02
Last Modified: 2012-05-11
How can write add hours with a date for the folloiwng case?

Supose today(30/04/2011) we are working from 7am to 3pm and tomorrow is a holiday and after tomorrow(2/05/2011) work starts at 7 and finish 5). if we get a repair work today and need 7 hours to finsih it, we have to add this 7 hours with the current date and time (let's say 10 am now) and it should display the finishing date and time. The remaining working hours need to added with the next work starting hours, if the next day is holiday (eg. Sunday), then the remaining hours should be added with Monday's starting time.

How can I achive it using sql stored procedure or c#?

Please give a sample or good links.

Question by:ayha1999
    LVL 11

    Assisted Solution

    Because you are using .NET you should go with the TimeSpan class to easily figure out times by performing mathematical calculations on dates. The DateTime objects that you are more than likely using also come with methods to add days/hours etc easily.

    Using SQL would be more complicated than using C#. Here is a link with a lot of examples on manipulating dates and times:
    LVL 7

    Author Comment

    Could u please give a sample in c# on how do it?


    LVL 19

    Accepted Solution

    Check the following link. It may help you to know more about the Parameter of Date Time....
    LVL 19

    Expert Comment

    by:Manoj Patil
    LVL 7

    Author Closing Comment


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now