Solved

DateTime Form

Posted on 2011-09-30
16
268 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 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

22 Experts available now in Live!

Get 1:1 Help Now