Click here to Skip to main content
15,891,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

my custom date format is Excel cell contains date value in the format Mon-YYYY.
example = excel cell contain apr-14 but actual cell value is 28-04-2014 and second cell value apr-14 but value is 13-04-2014.

but i used function following ways:
C#
public static DateTime? CleanDateField(string DateField)
    {

        double d = double.Parse(DateField);

        // Get the converted date from the OLE automation date.
        DateTime conv = DateTime.FromOADate(d);


        // Convert the text to DateTime and return the value or null
        DateTime? CleanDate = new DateTime();
        int intDate;
        bool DateIsInt = int.TryParse(DateField, out intDate);
        if (DateIsInt)
        {
            // If this is a serial date, convert it
            CleanDate = DateTime.FromOADate(intDate);
        }
        else if (DateField.Length != 0 && DateField != "1/1/0001 12:00:00 AM" &&
            DateField != "1/1/1753 12:00:00 AM")
        {
            // Convert from a General format
            CleanDate = (Convert.ToDateTime(DateField));
        }
        else
        {
            // Date is blank
            CleanDate = null;
        }
        return CleanDate;
    }


but i am getting cell values for apr-14 is 01-04-2014 which is wrong i have to retrieve date
values while importing
1) first cell value is 28-04-2014
2) second cell value is 13-04-2014

Plz help i search on google i did not find correct solution
thanks in advance
Posted
Comments
Laiju k 6-May-14 2:03am    
what is your code for getting values from excel

How are retrieving the data from excel.
are you using Gridview or you simply getting values from excel
sadhana4 6-May-14 2:33am    
string strTempPath = System.Configuration.ConfigurationManager.AppSettings["TempPath"].ToString();
string strFileName = fluplEarningsFile.FileName.ToString();
string strMainFilename = strTempPath + strFileName;
string oledbCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strMainFilename + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1'";
fluplEarningsFile.SaveAs(strTempPath + strFileName);
if (fluplEarningsFile.HasFile)
{
DataSet ds;
DataSet dssubsector;
OleDbDataAdapter dataadapter;
SqlConnection con = new SqlConnection(connString);
OleDbConnection OLEConn = new OleDbConnection(oledbCon);
OleDbCommand oledbComm = new OleDbCommand();
string strQuarterMonth;
string strQuarterYear;
oledbComm.Connection = OLEConn;
OLEConn.Open();
dataadapter = new System.Data.OleDb.OleDbDataAdapter(oledbComm);
string strSelect = "select * from [Earnings$]";
oledbComm.CommandText = strSelect;
ds = new System.Data.DataSet();
dataadapter.Fill(ds);

dataset is using to read data and update the table
sadhana4 6-May-14 3:18am    
plz tell me how to do

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900