Results 1 to 7 of 7

Thread: Round up date calc

  1. #1

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Round up date calc

    Guys,

    How do I round this UP to the actual number of weeks ?

    datediff(d,c.startdate,c.enddate)/7 as ContractPeriod

    Example, 10/10/05 - 15/06/07 is 87.57 weeks, I need to show this as 88.

    Thanks
    Bob
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Round up date calc

    Try
    VB Code:
    1. Private Sub Command1_Click()
    2. MsgBox Round(87.57)
    3. End Sub

  3. #3

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: Round up date calc

    Sorry, my mistake, I meant in my SQL view....

    ALTER view vw_Rpt_ContractorReport
    AS
    SELECT cr.*,
    c.ID AS Contract_ID,
    c.name as Contract_Name,
    c.startdate as ContractStartDate,
    c.enddate as ContractEndDate,
    datediff(d,c.startdate,c.enddate)/7 as ContractPeriod
    FROM ContractorReport cr
    Join Contract c on c.id = cr.Contract
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Round up date calc

    As the functions available vary significantly by DBMS, we will need to know which database system you are using.

  5. #5

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: Round up date calc

    Thanks for the response Si,

    I am using SQL Server 2000

    Bob
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  6. #6
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: Round up date calc

    Have you tried using ww as datepart parameter for the DATEDIFF function?

    Code:
    DATEDIFF(ww,c.startdate,c.enddate)

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Round up date calc

    Good point, but I don't think that would round up.

    I've just remembered a little trick tho, how about this:

    (datediff(d,c.startdate,c.enddate)+6)/7 as ContractPeriod

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