DaysBetweenDates

Modified on 2013/05/11 10:33 by Eugene — Categorized as: Community Components

Syntax


public static int DaysBetweenDates( this int fromDate, int toDate ) 
public static int DaysBetweenDates( this string fromDate, string toDate ) 

public int DaysBetweenDates( int fromDate, int toDate ) public int DaysBetweenDates( string fromDate, string toDate )

Parameter Description

fromDateStarting date
toDateEnding date

Description

Determines the number of calendar days including weekends between the two specified dates, Date1 and Date2, in yyyyMMdd format (which you can easily reconfigure by following the standard Date and Time Format specifiers list.

Two formats are supported as overrides: both dates as integer values, or both dates as string values.

Example

Example using C# extension methods:


using System;
using WealthLab;

public class DBDates: WealthScript { protected override void Execute() { string begDate = "20040112"; string endDate = "20080125"; int iBegDate = 20040112; int iEndDate = 20080125; PrintDebug( begDate.DaysBetweenDates( endDate ) ); PrintDebug( iBegDate.DaysBetweenDates( iEndDate ) ); } }

Legacy syntax example:


using System;
using WealthLab;
using Community.Components; // DaysBetweenDates here
/*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions ***/

public class DBDates: WealthScript { protected override void Execute() { // Create an instance of class that holds the method Calculate calc = new Calculate(this); // pass WealthScript as "this" string begDate = "20040112"; string endDate = "20080125"; int iBegDate = 20040112; int iEndDate = 20080125; PrintDebug( calc.DaysBetweenDates( begDate, endDate ) ); PrintDebug( calc.DaysBetweenDates( iBegDate, iEndDate ) ); } }