PC Review


Reply
Thread Tools Rate Thread

Convert date() to DateTime format

 
 
Ryan Ramsey
Guest
Posts: n/a
 
      21st Jul 2006
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..


 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      21st Jul 2006
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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a latebinded DataTable column's format from DateTime to string (or format the date time value) RSH Microsoft VB .NET 0 6th Dec 2006 03:49 PM
convert datetime to sortable format pranesh.nayak@gmail.com Microsoft Dot NET Framework 5 27th Aug 2006 07:53 PM
How to convert a date string to datetime value with custom date format? ABC Microsoft C# .NET 1 29th Sep 2005 11:11 AM
Any easy way to convert DateTime to Xml Date format Q. John Chen Microsoft C# .NET 2 8th Jul 2005 11:05 PM
DateTime problem: how to create datetime format hh:mm:ss AM/PM without the date mimi Microsoft C# .NET 1 6th Aug 2004 08:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:43 AM.