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

    Display of dates in excel by compare using

    Hi friends,
    I have excel sheet in that i inserted dates from 1-jan-16 to 31-jan-16.
    now i am reading dates from table1 , in table1 (sample dates are 3,4,7,11,16,22,26).

    now i want when i read 3-jan-16 date from database . i want to display the result in 3-jan-16 excel
    sheet where i placed static.

    so please suggest the code in to solve this problem.
  • #764508
    I assume that you are asking the following.

    1. Create one excel file
    2. Write dates in the cell.
    3. You have one database having some data. Based on the date you have to highlight the cell of the excel which has the same date right.

    If it was your requirement, you have to go for excel programing. You have to learn VBA Coding.

    Following is the sample VBA Code for connecting the database

    Private Sub Description_AfterGotFocus()
    Dim objRec
    Dim objConn
    Dim cmdString

    Set objRec = CreateObject("ADODB.Recordset")
    Set objConn = CreateObject("ADODB.Connection")

    objConn.ConnectionString = "Provider=MSDASQL;DSN=GreatPlains;Initial Catalog=TWO;User Id=sa;Password=password"

    cmdString = "Select * from from GL00105 )"

    Set objRec = objConn.Execute(cmdString)

    If objRec.EOF = True Then
    AccountMaintenance.UserDefined1 = ""
    AccountMaintenance.UserDefined1 = objRec!ACTINDX
    End If
    End Sub

    By Nathan
    Direction is important than speed

  • #764510
    What you want to do exactly ? compare date between excel and data ? or
    Basically when you export data to excel from database you need to specify the date format as below

    Range rg = (Excel.Range)worksheetobject.Cells[1,1];
    rg.EntireColumn.NumberFormat = "MM/DD/YYYY";

    hope it helps

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764527

    This is not a simple task; if you want to compare your Excel sheet data into database result you need to understand the both the structures and datatype formats, both should be in same format, if it is not in same then convert that into one unique format and then read the excel data as well as database data and compare both the result as you want.

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

    Blog :

  • #764570
    You can use given code snippet for Formatting DateTime in c#
     DateTime dob = new DateTime(2016, 02, 15);  
    string[] dateFormats = dob.GetDateTimeFormats();
    foreach (string format in dateFormats)

    More details about your query recommended following guideline

  • Sign In to post your comments