date format very simple

lblmessage.Text = reader["dateWeek"].ToString();
my dateWeek is returning date with time, I dont want to see time, just {0:M-dd-yyyy}  format I need.. how would I do that on cs code..
1jawsAsked:
Who is Participating?
 
HainKurtConnect With a Mentor Sr. System AnalystCommented:
I mean this

lblmessage.Text = String.Format("{0:M-dd-yyyy}",reader["dateWeek"]);
or
lblmessage.Text = String.Format("{0:M-dd-yyyy}",reader["dateWeek"].value);
0
 
milindsmCommented:
reader["dateWeek"].ToShortDateString()
0
 
Pratima PharandeCommented:
try this

 Response.Write(DateTime.Now.ToString("M-dd-yyyy"));

In your case

lblmessage.Text = reader["dateWeek"].ToString("M-dd-yyyy");
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
HainKurtSr. System AnalystCommented:
Format(reader["dateWeek"], "M-dd-yyyy")
or
Format(reader["dateWeek"].value, "M-dd-yyyy")
0
 
HainKurtSr. System AnalystCommented:
or
reader["dateWeek"].value.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);
or
reader["dateWeek"].ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);
0
 
1jawsAuthor Commented:
thanks for all for replying but for some reason none of them worked :(  

1) shordate thing didnt work
2)lblmessage.Text = reader["dateWeek"].ToString("M-dd-yyyy");   didnt work it says takes 1 argument
3)hainkurt your last post I dont want to even user Culture info stuff and your first post didnt work either.
0
 
milindsmConnect With a Mentor Commented:
ToShortDateString is not even compiling or giving wrong results??? Are you sure reader["dateWeek"] is returning Date and Time???? If not, first convert it to date and time and then use any one of the solutions above. It should work. Its quite straight forward.
0
 
HainKurtSr. System AnalystCommented:
ok use this then ;)

Response.Write(String.Format("{0:M-dd-yyyy}",DateTime.Now));
0
 
HainKurtSr. System AnalystCommented:
0
 
Pratima PharandeConnect With a Mentor Commented:
try this

 lblmessage.Text = Convert.ToDateTime(reader["dateWeek"]).ToString("M-dd-yyyy");
0
 
1jawsAuthor Commented:
hainkurts answer was correct. Thanks all!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.