Avatar billede hnteknik Novice
27. maj 2009 - 16:27 Der er 5 kommentarer og
1 løsning

Excel's Days360 Function

Jeg er røget ind i noget gsammels financiel prorata regning og skal bruge en funktion svarende til Excel's Days360 Function

functionen ser sådan ud DAYS360(start_date,end_date[,method])
der er en eu og us metode

Er der nogen, der kan fortælle mig om indholdet i den funktion til brug i Acess ?

Det er en gammel testamentisk måde at regne på - 30 dage per måned x 12
Avatar billede mugs Novice
27. maj 2009 - 16:38 #1
Kan du forklare nærmere hvad du vil opnå?
Avatar billede hnteknik Novice
27. maj 2009 - 16:50 #2
HM - en måde kunne være:

Function D360(begin_date, end_date)
D360 = Excel.WorksheetFunction.days360(begin_date, end_date, true)
End Function
Avatar billede hnteknik Novice
27. maj 2009 - 16:52 #3
>MUGS
Jeg skal bruge antal dage mellem to datoer i et 360 dages system formodentlig efter et EU baseret system.

Skal lige se, ast jeg kan bruge excel functionen direkte. Krævel vel at excell er installeret
Avatar billede hnteknik Novice
27. maj 2009 - 16:56 #4
Fandt denne SQL undersættelse

CREATE FUNCTION dbo.fnDays360
(
@startDate DateTime,
@endDate DateTime
)
RETURNS int
AS
BEGIN
RETURN (CASE WHEN Day(@endDate)=31 THEN 30 ELSE Day(@endDate) END) -
  (CASE WHEN Day(@startDate)=31 THEN 30 ELSE Day(@startDate) END)
  + ((DatePart(m, @endDate) + (DatePart(yyyy, @endDate) * 12))
  -(DatePart(m, @startDate) + (DatePart(yyyy, @startDate) * 12))) * 30
END
Avatar billede hnteknik Novice
27. maj 2009 - 16:59 #5
Her er en anden clon, somarbejder med både us og eu metode:

Excel DAYS360 clone
CREATE FUNCTION dbo.DATEDIFF360
(
    @source DATETIME,
    @target DATETIME,
    @style BIT = 0
)
RETURNS INT
AS
BEGIN
        RETURN  CASE @style
                    -- European style
                    WHEN 1 THEN CASE
                                    WHEN DATEPART(DAY, @target) = 31 THEN 30
                                    ELSE DATEPART(DAY, @target)
                                END
                                - CASE
                                      WHEN DATEPART(DAY, @source) = 31 THEN 30
                                      ELSE DATEPART(DAY, @source)
                                  END
                    -- US style
                    ELSE CASE
                            WHEN DATEPART(DAY, @target) = 31 AND DATEPART(DAYOFYEAR, @source) = 60 AND DATEPART(MONTH, @source) = 2 THEN 30
                            WHEN DATEPART(DAY, @target) = 31 AND DATEPART(DAY, @source) < 30 THEN 31
                            WHEN DATEPART(DAY, @target) = 31 THEN 30
                            ELSE DATEPART(DAY, @target)
                        END
                        - CASE
                              WHEN @source = DATEADD(MONTH, DATEDIFF(MONTH, -1, @source), -1) THEN 30
                              ELSE DATEPART(DAY, @source)
                          END
                END + 30 * DATEDIFF(MONTH, @source, @target)
END
Avatar billede hnteknik Novice
27. maj 2009 - 20:10 #6
Så har jeg bixer noget sammen som virker

Public Function DATEDIFF360(Start_Date As Date, Slut_Date As Date, EUStyle As Boolean)
If EUStyle Then
    DAGE = DATEPART2(Slut_Date) - DATEPART2(Start_Date)
Else
    If DatePart("D", Slut_Date) = 31 And DatePart("Y", Start_Date) = 60 And DatePart("M", Start_Date) = 2 Then
        DAGE = 30
    ElseIf DatePart("D", Slut_Date) = 31 And DatePart("D", Start_Date) < 30 Then
       
        DAGE = 31
    Else
        DAGE = DATEPART2(Slut_Date)
    End If
   
    If Start_Date = DateAdd("M", DateDiff("M", -1, Start_Date), -1) Then
        MINUSDAGE = 30
    Else
        MINUSDAGE = DatePart("D", Start_Date)
    End If
   
    DAGE = DAGE - MINUSDAGE
End If

    DATEDIFF360 = DAGE + 30 * DateDiff("M", Start_Date, Slut_Date)
End Function

Public Function DATEPART2(xDate As Date)
    If DatePart("D", xDate) = 31 Then
        DATEPART2 = 30
    Else
        DATEPART2 = DatePart("D", xDate)
    End If
End Function

Sub TEST()
MsgBox DATEDIFF360(#1/1/2009#, #3/21/2010#, True)
End Sub
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester