# Convert current timestamp to a decimal number with 10 digits

How can I convert the current timestamp to a decimal number of 10 digits in C#.

Example Date.Time.Now to some ten digit number representing the time
LVL 1
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
It would depend on how you want the time represented. For example. the number of elapsed seconds since some arbitrary start date.

Jim
0
Author Commented:
I am not sure if you mean the arbitary date something like  01-01-1900.

But here is an example of a decimal, whcih I am told represents a time.
4557350997

I would like to know what time it actually represents.
I need to convert current timestmap to some number
0
Commented:
That doesn't look like elapsed seconds - if so, it would be approximately 144.41 years. If you can find the representation from whatever source provided the number, it can be done. If you can get number-datetime pairs for some examples, It would probably be possible to deduce the algorithm to produce the numbers you need. Without one of those, it will be very difficult.

Jim

0
Author Commented:
the source is from a hexadecimal timestamp that I get from a db query. The timestamp is tored as Binary(8)
the following is the select
SELECT MIN(XTimeStamp) FROM TableData (nolock) WHERE LastModifyTime BETWEEN '01/28/2008' AND '01/28/200812:00:00.000'

and this is what it returns in hexadecimal format
000000010FA3A855

Which I then convert to decimal to give me
4557350997

So what I want to do is enter a decimal timestamp and do the reverse, meaning pass it aa a Binary(8) to a stored proc for processing
0
Commented:
Do you know which application currently writes XtimeStamp to the database? We know (or can find) the LastModify date and time. However, that doesn't necessarily bear a known relationship to XTimeStamp.

Jim
0
Author Commented:
Xtimestamp is just a column name in the table TableData, the column definition is Binary(8)
0
Commented:
you can explicitly convert from integer to varbinary:

select convert(varbinary(8),convert(bigint,4557350997))

result: 0x0A00000155A8A30F

The second cast was necessary because SQL apparently does not convert the constant to a bigint implicitly, so the result was different
0
Author Commented:
I need to take a timstamp example DateTime.Now and convert it a decimal with 10 digits
0
Commented:
I understand XTimeStamp is a column name. If there is data in that column, some application wrote it. That application presumably does the conversion you want. If you can find out from the authour of that application what algorithm is used to create the number, we can help you reproduce it.

Jim
0
Author Commented:
Jim,

All the information that I ahve is that the field is stored as binary(8) , when I query it I get something like this 0x000000010FA3A855.

So is it possible to do something like this and arrive to a decimal
DateTime.Now.Year * (some num) + DAteTime.Now.Month * (some num) + DateTime.Now.Day * (some number) + DateTime.Now.Hour * (some num) + DateTime.Now.Min * (some num) +  DateTime.Now.Sec * (some num)

0
Commented:
We can certainly accomplish something like that. However, something else is using that column as well. If we create the number in a different way, the other app will not be able to read it, and we will not be able to read what the other app writes.

If you can get some timestamp-number pairs, from the other application like:
0x000000010FA3A855 - 23 Jum 2007 16:45:32
0x000000010ED3A855 - 16 Apr 2007 16:45:32

Then we can probably deduce the algorithm used, and read and write numbers that match those written by the other application. Without the algorithm used by the other system, and without some sample pairs to analyze, there's simply no way to do what you need.

Jim
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Jim

I have no idea how those values are stored, I will ask the team soon.
If I do not have an answer by Tuesday, i will award you the points for all the above explantion you provided.

Thanks again for all your help
0
Commented:
No rush - I would like to see it working for you.

Jim
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.