DateTime Structure
http://www.csharpfriends.com
World's Greatest C# Community    
Home Articles C# Forums Books C# Syntax C# Spec C# Jobs free Source Code Advertise About
 

Control Panel

[ Sign In / register ]
Points   
Notes 
My Forums
My Tutorials
My Profile

Resources

Learn
 Articles
 QuickStarts
 C# Spec
 Whitepapers
 Tools
 Class Browser
 C# Code Generator
 Links
 Misc Rss Feeds
 Code Highlight
 411 Directory
 FREE magazines
 freevb.net

Reviews
  ASP.NET Hosting

Source Code
 Get Version 1.0



C# Consulting
AspDotNetStoreFront
Chapter:   Getting Started
Current Lesson:
DateTime Structure
[Latest Content]
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | ALL
[prev. Lesson]  Master Pages in ASP.NET 2.0 [next Lesson]  Visual Basic .NET Syntax Reference Primer
DateTime Structure
  by: webmaster

As you might have guessed, System.DateTime is an ASP.NET value type that represents dates and times. The datetime structures values can range from January 1st 0001 12:00 to December 31st 9999 11:59:59 PM (looks like a year 10 000 bug in the works!).

As for the time values, they are measured in 100-nanosecond unites which are also commonly known as 'ticks'.

The DateTime object will by default use the Gregorian calendar unless you explicitly pass a IFormatProvider parameter stating otherwise.

Some common methods of the DateTime structure are: Add, AddDays, AddHours, AddMinutes, AddMonths, AddSeconds, AddYears, DaysInMonth along with the various permuations of the ToString() overload for DateTime.

If you want to initialize the DateTime object with a value (which you have to do i.e. it cannot be null ofcourse) you can use DateTime.MinValue or DateTime.MaxValue.

For reference purposes I'm going to show you some common datetime formats below, this reference will come in handy when you are developing trust me!

Examples using DateTime in ASP.NET

Instead of explaining many of the common uses of the datetime structure, I've created an .aspx page that contains many of the common uses. I've included both the code and output for your viewing pleasure.

What you'll find in the examples:

  1. How to display the date in various formats using ToString().
  2. How to get the number of days in a month.
  3. How to add or subtract minutes, seconds, hours, days, months or even years from a date.
  4. How to compare two different datetimes.

Live Demo of DateTime Structure examples

Follow the link to view the examples, I will keep this example updated as I get more code snippets.


1 


Build Your Own ASP.NET Website Using C# & VB.NET

Chapter:  Getting Started
Current Lesson:
DateTime Structure
[Latest Content]
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | ALL
[prev. Lesson]  Master Pages in ASP.NET 2.0 [next Lesson]  Visual Basic .NET Syntax Reference Primer


Today's Top Movers
vulpes 6800
MadHatter 2220
jal 867
Jeff1203 857
muster 791

Yesterday Top Movers
shakti sin.. 9
MadHatter 3
C#fanatic 2
Al_Pennywo.. 2
ravikirank 1

Monthly Leaders
vulpes 6800
MadHatter 2260
jal 867
Jeff1203 857
muster 791

Top Members
mosessaur 18457
Rincewind 7074
stanleytan 6995
vulpes 6800
Gsuttie 6046

Great Offers
.net hosting
Go To My Pc
Remote Pc Control
zonealarm
spam blocker
web hosting directory
ad server   C#
snadtech GoToMyPc

Top of Page

Advertise | About | Link To Us | Privacy Notice Copyright © 2003 - 2005 CSharpFriends.com  All Rights Reserved  Visual C# Developer Center