?
Solved

date format very simple

Posted on 2009-12-21
11
Medium Priority
?
357 Views
Last Modified: 2012-05-08
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..
0
Comment
Question by:1jaws
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 8

Expert Comment

by:milindsm
ID: 26102238
reader["dateWeek"].ToShortDateString()
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 26102240
try this

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

In your case

lblmessage.Text = reader["dateWeek"].ToString("M-dd-yyyy");
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 26102242
Format(reader["dateWeek"], "M-dd-yyyy")
or
Format(reader["dateWeek"].value, "M-dd-yyyy")
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 61

Expert Comment

by:HainKurt
ID: 26102264
or
reader["dateWeek"].value.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);
or
reader["dateWeek"].ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);
0
 

Author Comment

by:1jaws
ID: 26102323
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
 
LVL 8

Assisted Solution

by:milindsm
milindsm earned 200 total points
ID: 26102334
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
 
LVL 61

Expert Comment

by:HainKurt
ID: 26102363
ok use this then ;)

Response.Write(String.Format("{0:M-dd-yyyy}",DateTime.Now));
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 26102366
0
 
LVL 61

Accepted Solution

by:
HainKurt earned 1600 total points
ID: 26102369
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
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 200 total points
ID: 26102391
try this

 lblmessage.Text = Convert.ToDateTime(reader["dateWeek"]).ToString("M-dd-yyyy");
0
 

Author Closing Comment

by:1jaws
ID: 31668855
hainkurts answer was correct. Thanks all!!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question