?
Solved

DateTime Form

Posted on 2011-09-30
16
Medium Priority
?
275 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 1000 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

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
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 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