Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
System Namespace
DateTime Structure
 Ticks Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
DateTime..::.Ticks Property

Gets the number of ticks that represent the date and time of this instance.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Public ReadOnly Property Ticks As Long
Visual Basic (Usage)
Dim instance As DateTime
Dim value As Long

value = instance.Ticks
C#
public long Ticks { get; }
Visual C++
public:
property long long Ticks {
    long long get ();
}
JScript
public function get Ticks () : long

Property Value

Type: System..::.Int64
The number of ticks that represent the date and time of this instance. The value is between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.

A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond.

The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001, which represents DateTime..::.MinValue.

The following example uses the Ticks property to display the number of ticks that have elapsed since the beginning of the twenty-first century and to instantiate a TimeSpan object. The TimeSpan object is then used to display the elapsed time using several other time intervals.

Visual Basic
Dim centuryBegin As Date = #1/1/2001 0:0:0#
Dim currentDate As Date = Date.Now
Dim elapsedTicks As Long = currentDate.Ticks - centuryBegin.Ticks
Dim elapsedSpan As New TimeSpan(elapsedTicks)

Console.WriteLine("Elapsed from the beginning of the century to {0:f}:", _
                   currentDate)
Console.WriteLine("   {0:N0} nanoseconds", elapsedTicks * 100)
Console.WriteLine("   {0:N0} ticks", elapsedTicks)
Console.WriteLine("   {0:N2} seconds", elapsedSpan.TotalSeconds)
Console.WriteLine("   {0:N2} minutes", elapsedSpan.TotalMinutes)
Console.WriteLine("   {0:N0} days, {1} hours, {2} minutes, {3} seconds", _
                  elapsedSpan.Days, elapsedSpan.Hours, _
                  elapsedSpan.Minutes, elapsedSpan.Seconds)
' If run on December 14, 2007, at 15:23, this example displays the
' following output to the console:
'          219,338,580,000,000,000 nanoseconds
'          2,193,385,800,000,000 ticks
'          219,338,580.00 seconds
'          3,655,643.00 minutes
'          2,538 days, 15 hours, 23 minutes, 0 seconds
C#
DateTime centuryBegin = new DateTime(2001, 1, 1);
DateTime currentDate = DateTime.Now;

long elapsedTicks = currentDate.Ticks - centuryBegin.Ticks;
TimeSpan elapsedSpan = new TimeSpan(elapsedTicks);

Console.WriteLine("Elapsed from the beginning of the century to {0:f}:", 
                   currentDate);
Console.WriteLine("   {0:N0} nanoseconds", elapsedTicks * 100);
Console.WriteLine("   {0:N0} ticks", elapsedTicks);
Console.WriteLine("   {0:N2} seconds", elapsedSpan.TotalSeconds);
Console.WriteLine("   {0:N2} minutes", elapsedSpan.TotalMinutes);
Console.WriteLine("   {0:N0} days, {1} hours, {2} minutes, {3} seconds", 
                  elapsedSpan.Days, elapsedSpan.Hours, 
                  elapsedSpan.Minutes, elapsedSpan.Seconds);
// If run on December 14, 2007, at 15:23, this example displays the
// following output to the console:
//    Elapsed from the beginning of the century to Friday, December 14, 2007 3:23 PM:
//          219,338,580,000,000,000 nanoseconds
//          2,193,385,800,000,000 ticks
//          219,338,580.00 seconds
//          3,655,643.00 minutes
//          2,538 days, 15 hours, 23 minutes, 0 seconds

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
DateTime.Ticks using PowerShell      Thomas Lee   |   Edit   |   Show History
# get-datetimeticks.ps1
# displays ticks from date/time
# Thomas Lee - tfl@psp.co.uk
 
# setup up dates
$centuryBegin = new-object System.DateTime 2001, 1, 1
$currentDate = [System.DateTime]::Now
$elapsedTicks = $currentDate.Ticks - $centuryBegin.Ticks
$elapsedSpan = new-object system.TimeSpan $elapsedTicks
  
# display output
"Current date: {0}" -f $currentdate
"Elapsed from the beginning of the century to {0:f}:" -f $currentDate
" {0:N0} nanoseconds" -f $($elapsedTicks * 1000)
" {0:N0} ticks" -f, $elapsedTicks
" {0:N2} seconds" -f $elapsedSpan.TotalSeconds
" {0:N2} minutes" -f $elapsedSpan.TotalMinutes
" {0:N0} days, {1} hours, {2} minutes, {3} seconds" -f $elapsedSpan.Days, $elapsedSpan.Hours,$elapsedSpan.Minutes, $elapsedSpan.Seconds

This script produces the following output:

PS C:\Documents and Settings\LeeT> D:\foo\get-datetimeticks.ps1
Current date: 20/04/2008 11:12:29
Elapsed from the beginning of the century to 20 April 2008 11:12:
2,303,827,494,000,000,000 nanoseconds
2,303,827,494,000,000 ticks
230,382,749.40 seconds
3,839,712.49 minutes
2,666 days, 11 hours, 12 minutes, 29 seconds


Mistake in the example      VincentS   |   Edit   |   Show History

I think there is another little mistake in the example. Usually a century starts at the year 00 and not at 01. At least here in Europe.
So to my opinion, the twenty-first century starts at 1-jan-2000.

Tags What's this?: Add a tag
Flag as ContentBug
Millenium Start Date      Dudicon   |   Edit   |   Show History

The start date of millenia is often debated even in the US. See the wikipedia article for a complete explanation: http://en.wikipedia.org/wiki/Millennium.

Tags What's this?: Add a tag
Flag as ContentBug
Millenium Start Date      Doug Kirschman   |   Edit   |   Show History
The start of the first millenium would be 1/1/0001. Can you imagine being around back then and saying... It is year zero? That is sort of silly.

For any other millenium, I agree that they begin on 1/1/XXX0. Either way, reasonable people can disagree on this issue.

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker