Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an existing system that is in XML Format that I am trying to parse and import into SQL. I'm having an issue with a particular field for dates. I was hoping someone could look at this and figure out what these numbers mean, because I have tried a lot of different things and can't figure it out.

<modifiedDate>1105323339</modifiedDate>
<createdDate>1097507448</createdDate>
<startDate>1097507448</startDate>
<date>1105323339</date>


The best I can come up with is that it's some sort of timespan, but not really sure. It does appear that they all have a similar number, but I can't figure out how to convert this to a VB.NET Date of any kind. I've tried

VB
Dim tspan As New TimeSpan(Convert.ToInt32(cNode.InnerText))
Dim createdDate As New Date(tspan.Ticks)

But it's not big enough to create a date out of it and it ends up just being a time.
Posted
Updated 30-Jan-12 10:03am
v3
Comments
Richard MacCutchan 30-Jan-12 15:06pm    
Dates are often based on some predefined 'epoch' start date, 0/0/0001, 1/1/1970 etc, so you may need to determine what that date is. Alternatively talk to the people who gave you the data.
speshulk926 30-Jan-12 15:18pm    
OK, I'll try to plug in some random dates and see if I get anything off of that.
speshulk926 30-Jan-12 15:38pm    
OK based on what you wrote I made a quick datetime picker that when I change the date it would update a label with the tick marks. I put in the 1/1/1970 date you said and I got a number pretty darn close. I kept back tracking it a bit and I got to 12/31/1969 8:00:00 PM against the date of 10/11/2004 11:10:48 PM gave me 10975074480000000. Can you think of any reason it would have dropped off the 0's at the end in the XML file or do I still have the wrong date even though everything else matches?

Edit: Sorry I updated the numbers at the top to reflect the actual numbers I am working with. The original post wasn't the first item that Visual Studio actually looked at. Having said that both number match minus the extra 0's at the end.
Alan N 30-Jan-12 16:16pm    
A DateTime tick is 100 nanoseconds. So losing 7 zeros converts ticks to seconds.
Richard MacCutchan 31-Jan-12 5:03am    
I have no idea. As I said earlier you really need to go back to the person or application that created these values and find out exactly what they are supposed to represent. Without that information you cannot move forward with any degree of certainty.

However ...
Assuming these numbers are time_t values they correspond to UTC times as follows:
<modifiedDate>1105323339</modifiedDate> 02:15:39 Mon Jan 10 2005
<createdDate>1097507448</createdDate> 16:10:48 Mon Oct 11 2004
<startDate>1097507448</startDate> 16:10:48 Mon Oct 11 2004
<date>1105323339</date> 02:15:39 Mon Jan 10 2005

1 solution

Basically, assuming that on input you are given the correct number of 100-ns tick counted from January 1, 0001 at 00:00:00.000 in the Gregorian calendar, you can construct the instance of System.DateTime using this constructor:
http://msdn.microsoft.com/en-us/library/z2xf7zzk.aspx[^].

If this is something else, you need to know what it is, and then obtain correct number of ticks, apparently by appropriate scaling and shifting. This is easy.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900