dosdatetimetofiletime (kernel32)
Last changed: -82.47.136.24

.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern bool DosDateTimeToFileTime(ushort wFatDate, ushort wFatTime,
   out UFILETIME lpFileTime);

User-Defined Types:

    public struct UFILETIME
    {
        public uint dwLowDateTime;
        public uint dwHighDateTime;
    }

Notes:

Sample and signature code originally used System.Runtime.InteropServices.FILETIME, but this uses ints instead of uints (DWORDs) meaning that this line:

    long hFT2 = (((long) ft.dwHighDateTime) << 32) + ft.dwLowDateTime;

gave incorrect results due to signs.

Tips & Tricks:

Please add some!

Alternate C# process:

    [DllImport("kernel32", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
    private static extern int DosDateTimeToFileTime(ushort dateValue, ushort timeValue, out UInt64 fileTime);

    [DllImport("kernel32", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
    private static extern int FileTimeToDosDateTime(ref UInt64 fileTimeInfo, out ushort dateValue, out ushort TimeValue);

    void Test()
    {
        UInt64 data = Convert.ToUInt64(DateTime.Now.ToFileTime());

        int result = 0;
        ushort dateValue = 0;
        ushort timeValue = 0;

        result = FileTimeToDosDateTime(ref data, out dateValue, out timeValue);
        data = 0;
        result = DosDateTimeToFileTime(dateValue, timeValue, out data);

       Console.Write(DateTime.FromFileTime(Convert.ToInt64(data)).ToString("MM/dd/yyyy hh:mm:ss tt"));
    }

Sample Code:

    public struct UFILETIME
    {
        public uint dwLowDateTime;
        public uint dwHighDateTime;
    }

    private static DateTime ConvertDosDateTime(ushort DosDate, ushort DosTime)
    {
        UFILETIME filetime = new UFILETIME();
        DosDateTimeToFileTime(DosDate, DosTime, out filetime);
        //Reference: http://www.aspemporium.com/howto.aspx?hid=26
        long longfiletime = (long)(((ulong)filetime.dwHighDateTime << 32) +
            (ulong)filetime.dwLowDateTime);
        return DateTime.FromFileTimeUtc(longfiletime);
    }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation