Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to convert dateTimepicker text to datetime in "dd-MMM-yy" format
Posted

Set Format property to "Custome" and "CustomeFormat" property type your desired format e.g. "dd-MMM-yy".
 
Share this answer
 
Comments
uspatel 25-Jul-11 5:07am    
this.IssueTableAdapter.Fill(this.IssueReportByDateDataSet.Issue, DateTime.Parse(dateTimePicker1.Text), DateTime.Parse(dateTimePicker2.Text));
now error occured
hi,
C#
DateTime tmpSentDate = temp_pager.SentDate;
                 string  StmpSentDate = string.Format("{0:d/M/yyyy}", tmpSentDate);


is this ok.
regards,
shefeek
 
Share this answer
 
try this

C#
string date = dateTimePicker1.Value.ToString("dd-MMM-yy");


This gives you 25-Jul-2011

Hope this helps
 
Share this answer
 
v2
Comments
uspatel 25-Jul-11 5:06am    
how to put 25-Jul-2011 into date time object
Wayne Gaylard 25-Jul-11 5:17am    
It is not possible to store 25-Jul-2011 as a DateTime object, as a DateTime holds just a Date and Time, it has no knowledge of how it is being displayed. That is where ToString() comes in. Put it this way, you would only ever need to represent the Date in such a manner when displaying the Date to a user. This would be in a TextBox, Label DataGrid etc, and you would then only need the string version. Hope this helps.
uspatel 25-Jul-11 5:23am    
But database table i have take Date/Time to Issueadte then how it will be inserted.
What's wrong with System.DateTime.ToString(string) or System.DateTime.ToString(IFormatProvider)?

In second case, use CultureInfo for IFormatProvider as this interface is implemented by CultureInfo, see code sample on the page referenced above.

See http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^]. See other ToString methods for more detail.

For time string formats, see http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^], http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

—SA
 
Share this answer
 

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