Results 1 to 3 of 3

Thread: Rounding time seconds up in SQL Server

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    64

    Rounding time seconds up in SQL Server

    Have two time values

    1900-01-01 00:59:47.000 need to round up to
    1900-01-01 01:00:00.000

    1900-01-01 00:19:23.000 need to round down to
    1900-01-01 00:19:00.000

    Perferably using a function or something that does both on the same column!
    Note the date above is the difference between as startdate and a enddate!

    thanks
    rag

  2. #2

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Rounding time seconds up in SQL Server

    Simply Converting/Casting datetime values to smalldatetime will perform the "rounding" you desire.

    Declare @StartDate datetime

    Set @StartDate = '1900-01-01 00:59:47.000'
    Print Cast(@StartDate as smalldatetime)

    Set @StartDate = '1900-01-01 00:19:29.000'
    Print Cast(@StartDate as smalldatetime)

    Jan 1 1900 1:00AM
    Jan 1 1900 12:19AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width