none
How do I convert the timestamp to actual DateTime?

Answers

  • Why thank you for the concise post, those of us who help are very busy and can't bother reading anything more than the title to diagnose a problem.

    What timestamp are you working from? In general DateTime.Parse or DateTime.ParseExact would be the most likely used for converting a time stamp string back to a DateTime object. MSDN has very good documentation on dealing with Parsing Date and Time Strings (time stamps) with this article.

    If you still need further help, then please elaborate on the situation so that we can provide related solutions.
    Monday, October 01, 2007 6:49 PM
  • The return from that function is an encoded date-time not number of seconds/milliseconds/ticks

    the format is: 0-4 second, 5-10 minute, 11-15 hour (0-23 not 0-12 + AM/PM), 16-20 Day, 21-24 Month, 25-31 years since 1980

    So you'll need to just decode the value into it's parts and shift them into the correct position
    Code Block

    uint i = 927629076;
    int seconds = (int)(i & 0x1F);
    int minutes = (int)((i & 0x7E0) >> 5);
    int hours = (int)(( i & 0xF800 ) >> 11);

    int day = (int)(( i & 0x1F0000 ) >> 16);
    int month = (int)(( i & 0x1E00000 ) >> 21);
    int YearsFrom1980 = (int)(( i & 0xFE000000 ) >> 25);

    DateTime b = new DateTime( 1980 + YearsFrom1980, month, day, hours, minutes, seconds );

    coincidentally this function will break in the year 2235... (max encoded # of years from 1980 is 254)
    Wednesday, October 10, 2007 3:30 PM

All replies

  • Why thank you for the concise post, those of us who help are very busy and can't bother reading anything more than the title to diagnose a problem.

    What timestamp are you working from? In general DateTime.Parse or DateTime.ParseExact would be the most likely used for converting a time stamp string back to a DateTime object. MSDN has very good documentation on dealing with Parsing Date and Time Strings (time stamps) with this article.

    If you still need further help, then please elaborate on the situation so that we can provide related solutions.
    Monday, October 01, 2007 6:49 PM
  • I'm very sorry guys. I didn't send that empty post intentionally. I vividly remember typing that post. Maybe it wasn't published due to some technical errors, in my side or the Microsoft side. I also couldn't reply to this post sooner, because for about last one week, I was getting a problem that whenever I clicked the 'My Threads' link, I got logged out. I was pissed off, until today I was able to visit this post and laughed at my mistake.

    But anyways, the question was how do I convert the MSDOS timestamp to DateTime. I am using a function which says in its documentation that it returns the MSDOS timestamp of the selected file. I get some number like 234565634. So i was wondering how do i interpret that type of number.
    Thanks.
    Wednesday, October 10, 2007 9:34 AM
  • Hi,

     

    It would be very good if you could find 2 examples on dates you know, and what they become in integer.

     

    Mabye it is seconds after 1980 or something, then you would write:

     

    DateTime d = new DateTime(1980,1,1);

    d.AddSeconds(234565634);

     

     

    With a few real dates it should be fairly easy to deduct what the dateformat is.

    Wednesday, October 10, 2007 9:51 AM
  • OK, here are the actual figures as I get from the function call.
    The function returns the number 927629076 for a text file which has the following properties:

    Created: October 10, 2007, 3:56:25 PM
    Modified: October 10, 2007, 3:56:39 PM
    Accessed: October 10, 2007, 3:56:39 PM


    I tried adding the number of seconds to 1970, Jan 1, but to no avail.
    Wednesday, October 10, 2007 10:13 AM
  • I need 1 more example to triangulate.

     

    Sadly i assume now it isn't seconds, because the number ended with 6, and neither 39 nor 25 ends with 6.
    Wednesday, October 10, 2007 2:32 PM
  • The return from that function is an encoded date-time not number of seconds/milliseconds/ticks

    the format is: 0-4 second, 5-10 minute, 11-15 hour (0-23 not 0-12 + AM/PM), 16-20 Day, 21-24 Month, 25-31 years since 1980

    So you'll need to just decode the value into it's parts and shift them into the correct position
    Code Block

    uint i = 927629076;
    int seconds = (int)(i & 0x1F);
    int minutes = (int)((i & 0x7E0) >> 5);
    int hours = (int)(( i & 0xF800 ) >> 11);

    int day = (int)(( i & 0x1F0000 ) >> 16);
    int month = (int)(( i & 0x1E00000 ) >> 21);
    int YearsFrom1980 = (int)(( i & 0xFE000000 ) >> 25);

    DateTime b = new DateTime( 1980 + YearsFrom1980, month, day, hours, minutes, seconds );

    coincidentally this function will break in the year 2235... (max encoded # of years from 1980 is 254)
    Wednesday, October 10, 2007 3:30 PM
  • Thanks Eric.
    Thursday, October 11, 2007 5:22 AM