Click here to Skip to main content
15,896,063 members
Home / Discussions / C#
   

C#

 
QuestionMySql Timestamp to C# DateTime conversion Pin
DerekT-P12-Sep-18 1:53
professionalDerekT-P12-Sep-18 1:53 
AnswerRe: MySql Timestamp to C# DateTime conversion Pin
Richard MacCutchan12-Sep-18 2:53
mveRichard MacCutchan12-Sep-18 2:53 
GeneralRe: MySql Timestamp to C# DateTime conversion Pin
DerekT-P12-Sep-18 23:23
professionalDerekT-P12-Sep-18 23:23 
GeneralRe: MySql Timestamp to C# DateTime conversion Pin
Richard MacCutchan13-Sep-18 2:03
mveRichard MacCutchan13-Sep-18 2:03 
GeneralRe: MySql Timestamp to C# DateTime conversion Pin
David A. Gray13-Sep-18 19:32
David A. Gray13-Sep-18 19:32 
GeneralRe: MySql Timestamp to C# DateTime conversion Pin
Richard MacCutchan13-Sep-18 21:36
mveRichard MacCutchan13-Sep-18 21:36 
GeneralRe: MySql Timestamp to C# DateTime conversion Pin
David A. Gray14-Sep-18 4:10
David A. Gray14-Sep-18 4:10 
AnswerRe: MySql Timestamp to C# DateTime conversion Pin
David A. Gray14-Sep-18 4:12
David A. Gray14-Sep-18 4:12 
The following statement in the article that you cited tells me enough to give a reasonable hint.

<blockquote class="quote"><div class="op">Quote:</div>Conversion of TIME or DATETIME values to numeric form (for example, by adding +0) results in a double-precision value with a microseconds part of .000000</blockquote>

The TIMESTAMP is a double-precision floating point number, which is interpreted as follows.

<ul>
<li>The fractional part, if nonzero, is the number of microseconds in the time.</li>
<li>The integral part is always present, is a Unix time.</li>
</ul>
With these two bits of information, you can use the following function, which you can implement as a static method, to convert the Unix timestamp.

<pre>public static DateTime UnixTimeStampToDateTime( double unixTimeStamp )
{
    // Unix timestamp is seconds past epoch
    System.DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc);
    dtDateTime = dtDateTime.AddSeconds( unixTimeStamp ).ToLocalTime();
    return dtDateTime;
}

The above is taken from the accepted answer to How can I convert a Unix timestamp to DateTime and vice versa?. Though I haven't tested it, I suspect it is at least essentially correct.

Since the input is double precision, you can amend it to handle the decimal part, which should be converted to ticks, where one tick is equal to 100 nanoseconds. The resulting tick count should then be added to the .Ticks property on the DateTime to get the final answer.

David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting

QuestionFind files in windows libraries Pin
Member 1342857811-Sep-18 12:03
Member 1342857811-Sep-18 12:03 
AnswerRe: Find files in windows libraries Pin
OriginalGriff11-Sep-18 20:16
mveOriginalGriff11-Sep-18 20:16 
AnswerRe: Find files in windows libraries Pin
Richard Deeming12-Sep-18 7:19
mveRichard Deeming12-Sep-18 7:19 
QuestionNot understanding use of return statement in c#. Pin
Hassan Y. Ansari11-Sep-18 6:08
Hassan Y. Ansari11-Sep-18 6:08 
AnswerRe: Not understanding use of return statement in c#. Pin
Ron Nicholson11-Sep-18 6:50
professionalRon Nicholson11-Sep-18 6:50 
GeneralRe: Not understanding use of return statement in c#. Pin
Hassan Y. Ansari11-Sep-18 18:49
Hassan Y. Ansari11-Sep-18 18:49 
GeneralRe: Not understanding use of return statement in c#. Pin
Pete O'Hanlon11-Sep-18 20:57
mvePete O'Hanlon11-Sep-18 20:57 
GeneralRe: Not understanding use of return statement in c#. Pin
Hassan Y. Ansari14-Sep-18 4:56
Hassan Y. Ansari14-Sep-18 4:56 
GeneralRe: Not understanding use of return statement in c#. Pin
Pete O'Hanlon15-Sep-18 6:24
mvePete O'Hanlon15-Sep-18 6:24 
AnswerRe: Not understanding use of return statement in c#. Pin
Pete O'Hanlon11-Sep-18 6:54
mvePete O'Hanlon11-Sep-18 6:54 
GeneralRe: Not understanding use of return statement in c#. Pin
OriginalGriff11-Sep-18 8:15
mveOriginalGriff11-Sep-18 8:15 
GeneralRe: Not understanding use of return statement in c#. Pin
Pete O'Hanlon11-Sep-18 8:46
mvePete O'Hanlon11-Sep-18 8:46 
Questiondesign website Could not find schema information for the element 'http://schemas.microsoft.com/.NetConfiguration/v2.0:configuration' ? Pin
Member 24584679-Sep-18 16:20
Member 24584679-Sep-18 16:20 
AnswerRe: design website Could not find schema information for the element 'http://schemas.microsoft.com/.NetConfiguration/v2.0:configuration' ? Pin
Matias Lopez12-Sep-18 10:31
Matias Lopez12-Sep-18 10:31 
QuestionEncrypt string to 10 random characters Pin
Mohammad Azeem9-Sep-18 10:13
Mohammad Azeem9-Sep-18 10:13 
AnswerRe: Encrypt string to 10 random characters Pin
Dave Kreskowiak9-Sep-18 10:59
mveDave Kreskowiak9-Sep-18 10:59 
AnswerRe: Encrypt string to 10 random characters Pin
Eddy Vluggen9-Sep-18 11:34
professionalEddy Vluggen9-Sep-18 11:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.