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

please help me! i want to format a datetime into string as
2013-11-15 or 2013/11/15....
ex: result: "15-Nov-2013"
thank so much!!!!!
Posted

If you are keeping it stored as a datetime, you can just do (Your DateTime Var).ToString("dd-MMM-yyyy")
 
Share this answer
 
Comments
alex giulio 16-Nov-13 5:21am    
hi, thank you, i have found my way!!!
Try this..

string str =Convert.ToDateTime("2013-11-15").ToString("dd-MMM-yyyy");
 
Share this answer
 
Comments
alex giulio 16-Nov-13 5:21am    
hi, thank you, i have found my way!!!
Did you try searching MSDN (or google) at all? Simple "c# date/time format string" would have brought you here: MSDN[^]
 
Share this answer
 
Try this:

C#
   DateTime dof = new DateTime();

System.Globalization.CultureInfo c1 = new System.Globalization.CultureInfo("en-GB", true);    
dof = DateTime.Parse(txtdate.Text.Trim(),  c1,System.Globalization.DateTimeStyles.NoCurrentDateDefault);
 
Share this answer
 
v2
Comments
alex giulio 16-Nov-13 5:11am    
thank you so much! i' try your way!!!
Tom Marvolo Riddle 16-Nov-13 5:38am    
welcome!
Hi VantyPro,

You can use this Datatime string
String dateNow = string.Format("{0}-{1:MMMM}-{2}",DateTime.Now.Date,DateTime.Now,DateTime.Now.Year);

Output will be like this:
15-November-2013

Try this
C#
enum monthToVal
        {
            JAN=1,FEB,MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
        }

String dateNow = string.Format("{0}-{1}-{2}",DateTime.Now.Day,(monthToVal)DateTime.Now.Month,DateTime.Now.Year);

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v2
Comments
alex giulio 16-Nov-13 5:16am    
thank, but i want result: 15-NOV-2013. i have searched on google but i can't do it. but i coded a function formating a datetime as:
public string ConvertDate(DateTime dt)
{
string result="";
string _month = "";
int day = dt.Day;
int month = dt.Month;
int year = dt.Year;
switch (month)
{
case 1:
_month = "JAN";
break;
case 2:
_month = "FEB";
break;
case 3:
_month = "MAR";
break;
case 4:
_month = "APR";
break;
case 5:
_month = "MAY";
break;
case 6:
_month = "JUN";
break;
case 7:
_month = "JUL";
break;
case 8:
_month = "AUG";
break;
case 9:
_month = "SEP";
break;
case 10:
_month = "OCT";
break;
case 11:
_month = "NOV";
break;
case 12:
_month = "DEC";
break;
}
result = day + "-" + _month + "-" + year;
return result;
}
♥…ЯҠ…♥ 18-Nov-13 9:16am    
updated my solution.....
alex giulio 19-Nov-13 20:20pm    
hi ,tks you!
alex giulio 19-Nov-13 20:20pm    
i'll try as ur!
You Can Write It Like This

string Dt=datetimepicker.value.tostring("dd/MM/yyyy");
 
Share this answer
 
Comments
alex giulio 18-Nov-13 21:34pm    
hi, tks. i have solved that proplem. thank you so much!

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