saurav2109
saurav2109

Reputation: 1

Date Time Format Issue

How can I convert DD/MM/YYYY (time is not here) date format to dd-MM-yyyy format. Please make sure I have only DD/MM/YYYY it includes no time and I want to convert it to dd-MM-YYYY format. Please help.

Upvotes: 0

Views: 312

Answers (3)

BrokenGlass
BrokenGlass

Reputation: 160852

You can use DateTime in .NET - example in C#:

DateTime inputTime = DateTime.ParseExact("11/01/2011", 
                                         "d/M/yyyy", 
                                         CultureInfo.InvariantCulture);
string outputTime = inputTime.ToString("dd-MM-yyyy");

Upvotes: 2

Abhishek B.
Abhishek B.

Reputation: 5202

In C# language
The Below code to import excel into dataset.

/************************** Code **********************************/
String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Book2.xls;" +
"Extended Properties=Excel 8.0;";

DataSet ds = new DataSet();
//You must use the $ after the object
//you reference in the spreadsheet
OleDbDataAdapter da = new OleDbDataAdapter
("SELECT * FROM [Sheet1$]", strConn);

//da.TableMappings.Add("Table", "ExcelTest");

da.Fill(ds);
DataTable _Dt = ds.Tables[0];
        foreach (DataRow row in _Dt.Rows)
        {   int outint=0;
            if(Int32.TryParse(Convert.ToString(row[0]),out outint))
            {
                // write your code here
                // if condition is true then it validate the integer otherwise it is not valid number format
            }
        }

/************************************************************/

Try it. Let you know if any problem.

Thanks Abhishek

Upvotes: 0

Abhishek B.
Abhishek B.

Reputation: 5202

in C# language Code.

string from = "17/5/1983";
DateTime dt = DateTime.ParseExact(from, "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture).Date;
string to = dt.ToString("dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);

Out Put : 17-05-1983

String to returns your expected DateTime format.. I tried, It works fine.

Try this code It convert datetime format into the "DD-MM-YYYY" format

Here's the MSDN Documentation on the subject: Custom Date and Time Format Strings

Please Mark As a Answer.

  • Thanks
    Abhishek

Upvotes: 3

Related Questions