473,395 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

convert date to ticks

How to convert a given date to its equvalent ticks.:
string d="5/15/2006 12:10:44 PM";

// string 2 date ...
dt=Convert.ToDateTime(d);

// Date 2 ticks ...
dt2ticks=dt.Ticks;
string ticks = Convert.ToString(dt2ticks);
Console.WriteLine("Input date: {0} Ticks: {1} ",d, ticks);

Though there is no error, I get the wrong ticks:
632832918440000000

This ticks number is used to query AD: last logon time (ADSI) and it is
not giving correct results.

I was trying to build a small console apps where in the date in
mm/dd/yyyy format is a command line parameter and the apps prints out
the equvalent ticks ???

Nov 27 '06 #1
1 6863
raghu1 <Ch**************@yahoo.comwrote:
How to convert a given date to its equvalent ticks.:
string d="5/15/2006 12:10:44 PM";

// string 2 date ...
dt=Convert.ToDateTime(d);

// Date 2 ticks ...
dt2ticks=dt.Ticks;
string ticks = Convert.ToString(dt2ticks);

Console.WriteLine("Input date: {0} Ticks: {1} ",d, ticks);

Though there is no error, I get the wrong ticks:
632832918440000000
In what way is that "wrong"? From the docs for the property:

<quote>
The value of this property represents the number of 100-nanosecond
intervals that have elapsed since 12:00:00 midnight, January 1, 0001.
</quote>

632832918440000000x100ns = 63,283,291,844s
= 17,578,692.2 hours
= 732,445.507 days
~= 2005.3 years

Looks about right to me.
This ticks number is used to query AD: last logon time (ADSI) and it is
not giving correct results.
Chances are that you don't want the same kind of ticks as the property
is giving you. Do you have docs for the parameter you're passing and
exactly what it should be?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Num | last post by:
Hi all, I have to convert a J2EE date as a long ("Millis") in a .NET date as a long ("Ticks") In Java, currentTimeMillis, is the difference, measured in milliseconds, between the current time...
1
by: Logan X via .NET 247 | last post by:
It's official....Convert blows. I ran a number of tests converting a double to an integer usingboth Convert & CType. I *ASSUMED* that CType would piggy-back ontop of Convert, and that performance...
4
by: David | last post by:
We only know the system ticks count, but we have no date or time function. So we need the source code about solving the problem. I have googled several times and no good results. can u help me? ...
2
by: Remi Caron | last post by:
Hi, I took over an Visual Object project (Visual Clipper) in that language there is a function to: Convert a string containing a 32-bit binary date to a date data type. That function is called...
3
by: sparkle | last post by:
Hi, Does anybody know how to convert date to ticks from a dateTimePicker? What I'm using now isn't working. I'm trying to use a dateTimePicker to set an appointment in Outlook with a...
15
by: JenHu | last post by:
Hi expert, I have a data field (birthdate) contains a datetime datatype (mm/dd/yyyy), how can I convert to mmdd?? say, the birthday is 8/1/1979 and convert to mmdd DOB =...
29
by: james | last post by:
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old database file that has the date(s) stored in it as number of days. An...
17
by: Terry Jolly | last post by:
New to C# ---- How do I convert a Date to int? In VB6: Dim lDate as long lDate = CLng(Date) In C#
3
by: Gugale at Lincoln | last post by:
Hi, I am working on an application which uses date as a primary key. All my records are at least a few millisecond apart and are in the form "20070630T12:50:24.207". SQL Server has a precision...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.