Solved

DateTime Form

Posted on 2011-09-30
16
271 Views
Last Modified: 2012-05-12
Hello Experts,

I need to format the display of the following date format stored in my Database.

All dates in my DB are stored as xx/xx/xxxx 9/30/2011.

I need to format 9/30/2011 to the following below to a Label Control.
Friday, September 30, 2011

Thanks in advance!!!
0
Comment
Question by:asp_net2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
  • +2
16 Comments
 
LVL 22

Accepted Solution

by:
p_davis earned 250 total points
ID: 36892533
yourDateTime.ToString(dddd, MMMM dd, yyyy);
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36892561
__NO POINTS__

Make sure you put quotes around the format string in p_davis' suggestion:

yourDateTime.ToString("dddd, MMMM dd, yyyy");

Open in new window

0
 
LVL 40
ID: 36892569
p_davis forgot the "" around the format. I would also add the culture if you want to be sure that it will display in English:

yourDateTime.ToString("dddd, MMMM dd, yyyy",new System.Globalization.CultureInfo("en-US"))
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 22

Expert Comment

by:p_davis
ID: 36892579
i was in a rush to beat you kaufmed
0
 
LVL 22

Expert Comment

by:p_davis
ID: 36892584
and what's this _No POINTS_ stuff??
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36892590
and what's this _No POINTS_ stuff??
I just want to make sure that the author doesn't do a "click all who participated as answer" that happens all to frequently. You solved the issue; I just offered an addendum  = )
0
 
LVL 22

Expert Comment

by:p_davis
ID: 36892598
ah a nice person around here is rare... thanks -- i would be more than willing to share points tho' because you did correct an error.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36892611
ah a nice person around here is rare
Ah. You must be hanging out in the wrong circles...  We'll get you sorted out   :-p
0
 
LVL 4

Author Comment

by:asp_net2
ID: 36892930
All,

The label control that I'm binding the Date to is in a ListView Control. How can I format the Label in the ListView Control to what you are both suggesting I use for the format?

<asp:ListView ID="lvCoursesSchedule" runat="server">
                    <ItemTemplate>
                        <br />
                        <hr />
                        <br />
                        <h1>REGISTRATION</h1>
                        <asp:Label ID="Label1" Text='<%# Eval("csch_startdate")%>' runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:ListView>

Thanks in advance!!!
0
 
LVL 6

Expert Comment

by:ventaur
ID: 36892986
Use p_davis' format specifier as the second parameter of the Eval function.

<asp:Label ID="Label1" Text='<%# Eval("csch_startdate", "dddd, MMMM dd, yyyy")%>' runat="server"></asp:Label>

Open in new window

0
 
LVL 4

Author Comment

by:asp_net2
ID: 36893385
@ventaur:

Your Label solution did not work. When I run my application the Label5 Control is listed as dddd, MMMM dd, yyyy  but does not show the information in the DB only shows the format string.

<asp:Label ID="Label5" Text='<%# Eval("csch_startdate", "dddd, MMMM dd, yyyy")%>' runat="server"></asp:Label>
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 36893429
This is why I hate databinding expressions  ; )

Try it in this manner:

<asp:Label ID="Label5" Text='<%# string.Format("{0:dddd, MMMM dd, yyyy}", Eval("csch_startdate"))%>' runat="server"></asp:Label>

Open in new window

0
 
LVL 4

Author Comment

by:asp_net2
ID: 36893649
Hi kaufmed,

I just got it to work before your post :) However, I was able to get it to work using the following below. Is that okay?

<asp:Label ID="Label5" Text='<%# Eval("csch_startdate", "{0:D}")%>' runat="server"></asp:Label>
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36894000
Honestly, I don't use the markup data binding much, so I'd have to defer as to "Is that okay?". However, if that does work for you, then you should be able to exchange the "D" with the format specified by p_davis to get the output you mentioned in the OP. In other words:

<asp:Label ID="Label5" Text='<%# Eval("csch_startdate", "{0:dddd, MMMM dd, yyyy}")%>' runat="server"></asp:Label>

Open in new window

0
 
LVL 6

Expert Comment

by:ventaur
ID: 36894164
Yeah, I forgot the {0: token in front of the format. Sorry.
0
 
LVL 4

Author Closing Comment

by:asp_net2
ID: 36895034
Thank you both!!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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