Solved

DateTime Form

Posted on 2011-09-30
16
269 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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 …
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…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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