String format date using datareader

Hi,

I am using this line to pull out the date from a datareader linked to an sql statement.


                        lbl_wall.Text = "<span style='font-size:12px;color:#555; font-style:italic'>Member since - " + String.Format("{0:ddd, MMM d, yyyy}", dbReaderPr["date_added"].ToString()) +"</span>";

The date format should be like:-

“Sun, Mar 9, 2008”

But it appears like this:-

“1/28/2010 8:00:16 AM”

How can i fix this?

Regards
Billy

The issue is the String.Format is looking for a date but is getting a string. Try this:


lbl_wall.Text = "<span style='font-size:12px;color:#555; font-style:italic'>Member since - " + String.Format("{0:ddd, MMM d, yyyy}", Convert.ToDateTime(dbReaderPr["date_added"].ToString())) +"</span>"; 


String.Format(“{0:ddd, MMM d, yyyy}”, dbReaderPr[“date_added”])

no need to convert to date… string.Format will accept object

thanks guys!

:slight_smile: