You must Sign In to post a response.
  • Category: SQL Server

    Convert number to year month days in sql server

    Hi,

    convert number to year month days in sql server

    like 400 days 1 years 1 month 28 days like that format
  • #761363
    Hi

    What is exact input and exact output can you share here.

    try this query for separate YMD


    --Year
    select datediff(year,'02/02/2014',Getdate())
    -- Month
    select datediff(MONTH,'02/02/2014',Getdate())
    --Day
    select datediff(DAY,'02/02/2014',Getdate())

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761364
    hi

    i need out put like

    255 = 0 years, 8 months, 15 days
    888 = 2 years, 5 months, 8 days
    569 = 1 years, 6 months, 24 days
    989 = 2 years, 8 months, 19 days
    460 = 1 years, 3 months, 5 days

  • #761365
    i need out put like

    255 = 0 years, 8 months, 15 days
    888 = 2 years, 5 months, 8 days
    569 = 1 years, 6 months, 24 days
    989 = 2 years, 8 months, 19 days
    460 = 1 years, 3 months, 5 days

    in sql server

  • #761366
    Hi

    You can try this Query


    SELECT Year(GETDATE())-DATEPART(yyyy,'04/02/1981') AS Year,MONTH(GETDATE())-DATEPART(mm,'04/02/1981') AS Month, DAY(GETDATE())-DATEPART(dd,'04/02/1981') AS Days


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761367
    hi

    can you share more information

    what do you exact need what is your input ?

    then i check output

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761368

    Use the following query


    declare @CountL int
    declare @YearCount int
    declare @MonthCount int
    declare @DayCount int
    set @CountL = 460
    set @YearCount = @CountL/365
    set @MonthCount = (@CountL - 365 * @YearCount) / 30
    set @DayCount = @CountL - ((@YearCount * 365) + (@MonthCount * 30))
    select @CountL , @YearCount , @MonthCount , @DayCount


    By Nathan
    Direction is important than speed

  • #761373
    thanks to all


Sign In to post your comments