Solved

DateTime Form

Posted on 2011-09-30
16
267 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
  • 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 74

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
 
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 74

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 74

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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 74

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 74

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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!
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now