Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 624135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:10:04+00:00 2026-05-13T19:10:04+00:00

I have a SQL Server function which converts a nvarchar day duration setting into

  • 0

I have a SQL Server function which converts a nvarchar day duration setting into a datetime value.

The day duration format is >days<.>hours<:>minutes<, for instance 1.2:00 for one day and two hours.

The format of the day duration setting can not be changed, and we can be sure that all data is correctly formatted and present.

Giving the function a start time and the day duration setting it should return the end time.

For instance: 2010-01-02 13:30 ==> 2010-01-03 2:00

I’m using a combination of charindex, substring and convert methods to calculate the value,
which is kind of slow and akward. Is there any other way to directly convert this day duration setting into a datetime value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:10:05+00:00Added an answer on May 13, 2026 at 7:10 pm

    Not from what I can see. I would end up with a similar bit of SQL like you, using charindex etc. Unfortunately it’s down to the format the day duration is stored in. I know you can’t change it, but if it was in a different format then it would be a lot easier – the way I’d usually do this for example, is to rationalise the duration down to a base unit like minutes.

    Instead of storing 1.2:00 for 1 day and 2 hours, it would be (1 * 24 * 60) + (2 * 60) = 1560. This could then be used in a straightforward DATEADD on the original date (date part only).

    With the format you have, all approaches I can think of involve using CHARINDEX etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SQL Server 2005 I have an SQL Function (ftn_GetExampleTable) which returns a table with
I need to have a sql function which takes a valid SQL Server date
I have a SQL Server table-valued function which is created by me I have
I have a simple problem with SQL SERVER charindex function. DECLARE @VAR1 varchar SET
I have a function in SQL server 2008 that takes a string: 'A,B,C,D' and
I have an user defined table function in SQL Server that aggregate data from
I have a huge problem with the REPLACE SQL function in Microsoft SQL Server
I have a UDF in sql server. I want to call this function at
Possible Duplicate: Simulating group_concat MySQL function in MS SQL Server 2005? I have a
I have a SQL Server 2008 table with a DateTime column that I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.