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

Need to make date format 'dd MMM yyyy' on Load

txt_Date_Of_Loan.Text = ds.Tables["Loans"].Rows[0]["DATELOAN"].ToString();



protected void Page_Load(object sender, EventArgs e)
       {
           ///Load Begin
           if (!IsPostBack)
           {
               try
               {

                   txt_Date_Of_Loan.Text = ds.Tables["Loans"].Rows[0]["DATELOAN"].ToString();



Please assist
Posted

Assuming the DATELOAN property returns a valid datetime value, this is what you can do -
Try Convert.ToDateTime(ds.Tables["Loans"].Rows[0]["DATELOAN"]).ToString("dd MMM yyyy");

This should help you explore other formats - Custom Date and Time Format Strings[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Sep-14 23:27pm    
Sure, 5ed.
—SA
Abhinav S 2-Sep-14 23:28pm    
Thank you SA.
PIEBALDconsult 2-Sep-14 23:42pm    
Get the Convert out of there; just cast it.
Abhinav S 3-Sep-14 1:59am    
Cast can bad if the value is null.
PIEBALDconsult 3-Sep-14 9:32am    
And the code you show will handle DBNull.Value properly?
Hi, try this

var dt = ds.Tables["Loans"].Rows[0]["DATELOAN"];

txt_Date_Of_Loan.Text = String.Format("{0:dd, MMMM, yyyy}", dt);
 
Share this answer
 
Comments
PIEBALDconsult 2-Sep-14 23:43pm    
That's the best one so far.

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