VB 6.0 - How to get in between days - Asked By menaka lingam on 06-Jan-12 06:58 AM

In my program ,i have From date field i.e "02/01/2012" and To date field i.e "07/01/2012".how to get in between days in this format "dd/MM/yyyy".
Jitendra Faye replied to menaka lingam on 06-Jan-12 07:06 AM
Try this-

public ArrayList BetweenDates(string startDate, string endDate)
    {
      DateTime sdt = DateTime.ParseExact(startDate, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
      DateTime edt = DateTime.ParseExact(endDate, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
      ArrayList dates = new ArrayList();       
      do
      {
 
        if (Days.Contains(sdt.DayOfWeek.ToString()))
        {
          dates.Add(sdt.Date.ToString("yyyy-MM-dd"));          
        }
        sdt = sdt.AddDays(1);
      } while (sdt.CompareTo(edt) != 1);
      return dates;
    }
smr replied to menaka lingam on 06-Jan-12 07:07 AM
hi

It was an easy job with classic VB to find difference between 2 dates or times. Even though it is not very difficult, it is a tricky and confusing thing in C# and VB.NET.

See the following sample code, which demonstrates how to calculate the difference between two DateTime objects using C# syntax.


DateTime startTime = DateTime.Now;

DateTime endTime = DateTime.Now.AddSeconds( 75 );

TimeSpan span = endTime.Subtract ( startTime );
Console.WriteLine( "Time Difference (seconds): " + span.Seconds );
Console.WriteLine( "Time Difference (minutes): " + span.Minutes );
Console.WriteLine( "Time Difference (hours): " + span.Hours );
Console.WriteLine( "Time Difference (days): " + span.Days );

follow
http://www.dotnetspider.com/resources/458-How-find-difference-between-two-Dates-C-or.aspx