By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,962 Members | 1,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,962 IT Pros & Developers. It's quick & easy.

Convert date() to DateTime format

P: n/a
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..
Jul 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Ryan Ramsey wrote:
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

Jul 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.