Click to See Complete Forum and Search --> : Date
Technocrat
Mar 8th, 2001, 10:53 AM
Anyone know how to easily change that stupid int of date and time of the DATE type to a normal looking string?
Technocrat
Mar 8th, 2001, 05:30 PM
Incase any one cares here is what you can do
DATE d = 36957.5638888889; // 03/07/2001 01:32:00 PMb
FILETIME ft = {0, 0};
SYSTEMTIME st = {1899, 12, 0, 30, 0, 0, 0}; // zero-date for DATE
// convert zero-date to FILETIME
SystemTimeToFileTime(&st, &ft);// convert zero-date FILETIME to large integer so we could do some math
ULARGE_INTEGER ulBase;
ulBase.LowPart = ft.dwLowDateTime;
ulBase.HighPart = ft.dwHighDateTime;// convert our DATE to large integer so we could add it to a base
ULARGE_INTEGER ulDateTime;
ulDateTime.QuadPart = d*(24*60*60); // seconds in a DATE
ulDateTime.QuadPart *= 10000000;// convert to 100-nanoseconds
// add the zero-date valueul
DateTime.QuadPart += ulBase.QuadPart;
// convert back to FILETIME
ft.dwLowDateTime = ulDateTime.LowPart;
ft.dwHighDateTime = ulDateTime.HighPart; // now, get the SYSTEMTIME value of original
DATEFileTimeToSystemTime(&ft, &st);
Chris
Mar 10th, 2001, 12:17 PM
Technocrat, hope this will help. Although it is in VB.
Option Explicit
'//WIN32API declare
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, ByVal " & _
"dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_WRITE = &H2
Private Const FILE_SHARE_READ = &H1
Private Const OPEN_EXISTING = 3
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_FLAG_RANDOM_ACCESS = &H10000000
'//WIN32API declare
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
'//WIN32API type declare
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Private ft_create As FILETIME
Private ft_last_access As FILETIME
Private ft_last_write As FILETIME
Private st As SYSTEMTIME
Private tz As TIME_ZONE_INFORMATION
Private hFile As Long
Private Sub CmdPath_Click()
On Error GoTo ErrHandle
With CDlg
.DialogTitle = "Open File..."
.ShowOpen
txtFile.Text = .FileName
Read_FileDateTime
End With
Exit Sub
ErrHandle:
End Sub
Chris
Mar 10th, 2001, 12:18 PM
Continue previous post...
Private Sub Read_FileDateTime()
Dim tmp As String
If Len(txtFile.Text) = 0 Then Exit Sub
'//open the File
hFile = CreateFile(txtFile.Text, _
GENERIC_READ Or GENERIC_WRITE, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, _
ByVal 0&, _
OPEN_EXISTING, _
FILE_ATTRIBUTE_NORMAL Or FILE_FLAG_RANDOM_ACCESS, _
0)
If hFile > 0 Then
'//Get the FileDateTime
GetFileTime hFile, ft_create, ft_last_access, ft_last_write
'//Get the time Zone Bias
GetTimeZoneInformation tz
'//Convert the date time to System date time
tmp = ""
FileTimeToSystemTime ft_create, st
tmp = Format(Str$(st.wDay) & "/" & Trim(Str$(st.wMonth)) & "/" & Trim(Str$(st.wYear)), "dddd, mmmm d yyyy") & " " & Format(CInt(Trim(Str$(st.wHour))) - (tz.Bias / 60) & ":" & Trim(Str$(st.wMinute)) & ":" & Trim(Str$(st.wSecond)), "hh:nn:ss AMPM")
lblInfo.Caption = Space(4) & "Create : " & tmp & vbCrLf
FileTimeToSystemTime ft_last_access, st
tmp = Format(Str$(st.wDay) & "/" & Trim(Str$(st.wMonth)) & "/" & Trim(Str$(st.wYear)), "dddd, mmmm d yyyy") & " " & Format(CInt(Trim(Str$(st.wHour))) - (tz.Bias / 60) & ":" & Trim(Str$(st.wMinute)) & ":" & Trim(Str$(st.wSecond)), "hh:nn:ss AMPM")
lblInfo.Caption = lblInfo.Caption & Space(5) & "Last Access : " & tmp & vbCrLf
FileTimeToSystemTime ft_last_write, st
tmp = Format(Str$(st.wDay) & "/" & Trim(Str$(st.wMonth)) & "/" & Trim(Str$(st.wYear)), "dddd, mmmm d yyyy") & " " & Format(CInt(Trim(Str$(st.wHour))) - (tz.Bias / 60) & ":" & Trim(Str$(st.wMinute)) & ":" & Trim(Str$(st.wSecond)), "hh:nn:ss AMPM")
lblInfo.Caption = lblInfo.Caption & Space(5) & "Last Write : " & tmp & vbCrLf
lblInfo.ForeColor = vbBlue
Else
lblInfo.Caption = "File not found!"
lblInfo.ForeColor = vbRed
End If
'//Close the File handle
CloseHandle hFile
End Sub
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.