Convert date() to DateTime format

R

Ryan Ramsey

I am trying to convert a value returned from the date() function in php 5.0
to a format .NET can use.

DateTime dt_now = DateTime.Now;
DateTime dt_last = new DateTime(Convert.ToInt32(dkpLast[0][1]));
TimeSpan dt_diff = dt_now.Subtract(dt_last);

the value returned to dt_last is 1153455444 which is rougly July 20th ~ 10pm

When I compare this to dt_diff I get a delta value (via dt_diff.Days) of
roughly 73,000 days.

Im sure I am doing this wrong but I have scoured the web and there isn't
much information.

Please help... The object is to compare the current date vs. the date
returned and to derive how old the event is via dt_diff..
 
J

Jon Skeet [C# MVP]

Ryan said:
I am trying to convert a value returned from the date() function in php 5.0
to a format .NET can use.

DateTime dt_now = DateTime.Now;
DateTime dt_last = new DateTime(Convert.ToInt32(dkpLast[0][1]));
TimeSpan dt_diff = dt_now.Subtract(dt_last);

the value returned to dt_last is 1153455444 which is rougly July 20th ~ 10pm

When I compare this to dt_diff I get a delta value (via dt_diff.Days) of
roughly 73,000 days.

According to the documentation for PHP, the number you're talking about
is the number of seconds since the first of January 1970 - whereas the
constructor you're using is taking ticks (not seconds) since the first
of January 1AD.

Here's some code to convert the seconds you've got into a DateTime:
DateTime epoch = new DateTime(1970, 1, 1);
DateTime date = epoch.AddSeconds(1153455444);

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top