Haseeb Ahmad

hi,

I need to convert a date time value to file time, i tried this ....

FILETIME ft = new FILETIME();

//from System.DateTime to System.Runtime.InteropServices.ComTypes.FILETIME

/////////////////////////////////////////////////////////////////

long hFT1 = DateTime.Now.ToFileTime();

ft.dwLowDateTime = (int)(hFT1 & 0xFFFFFFFF);

ft.dwHighDateTime = (int)(hFT1 >> 32);

/////////////////////////////////////////////////////////////////

in order to check that conversion is right I converted file time back to date time using this code ...

/////////////////////////////////////////////////////////////////

//from System.Runtime.InteropServices.ComTypes.FILETIME to System.DateTime

/////////////////////////////////////////////////////////////////

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

DateTime dte = DateTime.FromFileTime(hFT2);

but this 'dte' is a wrong value.

i think the problem is : FILETIME.dwLowDateTime is a signed int and if 32nd bit of long value is '1' , the FILETIME.dwLowDateTime is converted to negative value.

PLz help me for correct conversion of datetime to filetime.

Regards,




Re: Visual C# General Conversion of DateTime to FILETIME

Khin

hi...

hope this can help you...

FILETIME ft = new FILETIME();

//from System.DateTime to System.Runtime.InteropServices.FILETIME

long hFT1 = DateTime.Now.ToFileTimeUtc();
ft.dwLowDateTime = (int) (hFT1 & 0xFFFFFFFF);
ft.dwHighDateTime = (int) (hFT1 >> 32);

good luck.

if this can help please click "YES", thanks





Re: Visual C# General Conversion of DateTime to FILETIME

Haseeb Ahmad

thanx dear but same problem persists (for some dates both work fine probably for those that has 32nd bit 0 but for some it dosent)