Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 22nd, 2008, 06:47 PM
Registered User
 
Join Date: Sep 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Formatting and creating date and Time

Formatting the date and Time so that it appears on every web page.

I have been trying to insert the date and time so that it appears on every page within the website. I do not know anything about Visual Basic and or C# but I'm slowing getting the feel using VWD 2008/ASP.NET3.5 so please bear with my ignorance when referencing codes as to where the code should go and what language is the code in.

I managed to come up with the date and time but it show in numbers.

Example: I would love to have the date and time displayed as follows.
Monday, September 22, 2008.

All I'm able to do is 09/092008, and it's boring.

 I have tried searching this forum but as someone very very new to ASP.NET, it gets confusing when you don't know which way is the best way to do something.



Any suggestions/Help.

Thanks very much.

 Audioicon.

 
Old September 22nd, 2008, 07:19 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Well, thanks to old-fashioned VB, VB.NET still has the simplest way to do this:

FormatDateTime( Date(), DateFormat.LongDate )

http://msdn.microsoft.com/en-us/library/a912f2a0(VS.80).aspx

If you want to do it in C# and/or be more ".NET-ish", you should use the System.DateTime structure.

So something like
   System.DateTime.Today.ToLongDateString()
will work in either language.

You can also get very, very explicit and get all kinds of weird formats, if you like:
   System.DateTime.Today.ToString("dddd, MMMM dd, yyyy")
again, works in either language.

TONS of documentation and examples on this, so hard to see how you missed it. When in doubt, go to the source: MSDN. Example:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

For the complete docs on DateTime:
http://msdn.microsoft.com/en-us/libr...e_members.aspx
 
Old September 22nd, 2008, 07:46 PM
Registered User
 
Join Date: Sep 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Old Pedant
 Well, thanks to old-fashioned VB, VB.NET still has the simplest way to do this:

FormatDateTime( Date(), DateFormat.LongDate )

http://msdn.microsoft.com/en-us/library/a912f2a0(VS.80).aspx

If you want to do it in C# and/or be more ".NET-ish", you should use the System.DateTime structure.

So something like
System.DateTime.Today.ToLongDateString()
will work in either language.

You can also get very, very explicit and get all kinds of weird formats, if you like:
System.DateTime.Today.ToString("dddd, MMMM dd, yyyy")
again, works in either language.

TONS of documentation and examples on this, so hard to see how you missed it. When in doubt, go to the source: MSDN. Example:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

For the complete docs on DateTime:
http://msdn.microsoft.com/en-us/libr...e_members.aspx
Thanks for the response but where in the page do you write the code? In the aspx page or the aspx.cs page?

I was hoping that since Visual Web developer had these web controls, it would also have a Date and Time web control you can just drag to the stage in design view.
I'm still learning the language and it's easy when I can add a control and see how the code works, just like the book I just bought.

Audioicon

 
Old September 22nd, 2008, 07:58 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

The usual answer to all programming questions: "It depends".

You *could* do it right on your .aspx page.

Right in the middle of the HTML and the ASP.NET tags, you could simply do
    <%= System.DateTime.Today.ToLongDateString()%>
And it will be just dumped, as text, right out into your page.

But if you want it to appear in a box or a label or or or...well, "It depends." Yes, you could do it in code behind by doing something like
    myDateTimeLabel.Text = System.DateTime.Today.ToLongDateString();
but I'm reluctant to say more without knowing your specifics.

I'm afraid you're going to have to begin to learn *some* of the fundamentals of programming. ASP.NET was never designed to be a 100% "drag and drop" environment. Visual Studio helps you out a lot, but it won't (and can't) do everything for you.

If you aren't working your way through some of the tutorials at http://msdn.microsoft.com/Express already, it's time to start doing so.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Time Output braunj ASP.NET 2.0 Basics 0 October 6th, 2008 10:27 PM
formatting date time Adam H-W Classic ASP Basics 4 September 29th, 2004 03:35 AM
Formatting a Field Containing a Time to AM/PM taleriana XSLT 2 March 16th, 2004 11:10 PM
Time: formatting from seconds to serial comets Classic ASP Basics 2 July 22nd, 2003 04:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.