?
Solved

Convert to DateTime object

Posted on 2004-08-19
5
Medium Priority
?
634 Views
Last Modified: 2012-06-21
I have a FileData object called myfile.

How do I convert the lastWriteTime_highDateTime and lastWriteTime_lowDateTime properties to a normal DateTime object?

Please ask if need more info.

Thanks
0
Comment
Question by:imt21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 7

Expert Comment

by:NipNFriar_Tuck
ID: 11842094
Why not use FileInfo? i.e.

FileInfo fi = new FileInfo( "fullFilePath" );
DateTime dt = fi.LastWriteTime;

Other than that what type of object is lastWriteTime_*?
0
 
LVL 1

Expert Comment

by:chmohan
ID: 11842172
System.DateTime dtTime = new DateTime();
dtTime.Hour,dtTime.Minutes.dtTime.Year ,assign these values from your property values
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 1000 total points
ID: 11842238
This should do the trick:

  [System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError=true)] static extern int FileTimeToSystemTime(ref FILETIME lpFileTime, ref SystemTime lpSystemTime);

    struct FILETIME
    {
      public int dwLowDateTime;
      public int dwHighDateTime;
    }

    struct SystemTime
    {
      public short wYear;
      public short wMonth;
      public short wDayOfWeek;
      public short wDay;
      public short wHour;
      public short wMinute;
      public short wSecond;
      public short wMilliseconds;
    }

    static DateTime GetDateTime(int dwLowDateTime, int dwHighDateTime)
    {
      FILETIME fileTime = new FILETIME();
      fileTime.dwLowDateTime = dwLowDateTime;
      fileTime.dwHighDateTime = dwHighDateTime;

      SystemTime systemTime = new SystemTime();
      FileTimeToSystemTime(ref fileTime, ref systemTime);

      return new DateTime(systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour, systemTime.wMinute, systemTime.wSecond, systemTime.wMilliseconds);
    }

Just call GetDateTime with your low and high time properties from your FileData object.
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 11842591
imt21, could you provide a sample of the values in lastWriteTime_highDateTime, and lastWriteTime_lowDateTime along with the actual Date/Time reported by Windows?
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 11842905
Actually, nevermind my last request - I found the values I needed to test.  The .NET Framework offers a method that will allow you to avoid another API call:

  DateTime.FromFileTimeUtc(dwLowDateTime + ((long)dwHighDateTime << 32))

Will return a DateTime object based on the low and high time properties from your FileData object (Which will match the FileTimeToSystemTime call).

Hope this helps!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question