You must Sign In to post a response.
  • Category: .NET

    How to Fixed this Date Issue

    Hi

    I have from date and Todate fields When i enter the fromdate and todate i need between date with days bind in gridview how will do this any one fixed this issue.
  • #764085
    Hi,

    Please refer following code snippet:

    DateTime dt1 = Convert.ToDateTime(textBox1.Text); //.. textBox1 accepts FromDate
    DateTime dt2 = Convert.ToDateTime(textBox2.Text);//.. textBox2 accepts ToDate
    List<DateTime> allDates = new List<DateTime>();
    for (DateTime date = dt1; date <= dt2; date = date.AddDays(1))
    {
    allDates.Add(date);
    }
    dataGridView1.DataSource = allDates; //.. Here binding whole List to DataGridView allows you to get all the details related to particular date for that row, depending on which you can modify your DataGridView to hide/show the desired columns.

    Hope this will help you.

    Regards,
    Shashikant Gurav[Programmer II],
    shashikantgurav22@gmail.com

  • #764091
    Hi,

    As per my understanding the post you want to display the date and datenames between 2 dates.

    If this is your requirement refer below sample code and bind the result to your grid.




    DECLARE @START_DATE DATETIME='2013-06-01'

    DECLARE @END_DATE DATETIME ='2013-06-29'

    DECLARE @END_COUNT INT=(SELECT DATEDIFF(DAY,@START_DATE,@END_DATE))

    DECLARE @START_COUNT INT=0
    DECLARE @NUMBER INT=1

    WHILE (@START_COUNT < @END_COUNT)

    BEGIN

    DECLARE @RESULT VARCHAR(1000)=(SELECT DATENAME(DW, DATEADD(DAY,@NUMBER,@START_DATE)) as Date_Names)
    SET @START_COUNT=@START_COUNT+1
    SET @NUMBER=@NUMBER+1
    PRINT @RESULT
    END


    Hope this will help you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments