I want to find the date a file was created on the users hard drive. I can find it by using API's but it returns the time in UTC. Anyone know how to either convert UTC time or an API that will get the time in a format I can read?
Printable View
I want to find the date a file was created on the users hard drive. I can find it by using API's but it returns the time in UTC. Anyone know how to either convert UTC time or an API that will get the time in a format I can read?
You can find the Creation/Last Modification Date/Time using the VB Function FileDateTime(), eg.
Caption = FileDateTime("C:\MyFile.txt")
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
[This message has been edited by Aaron Young (edited 11-24-1999).]
Thanks. I don't know why I thought I had to use an API. I guess you get going in one direction and can not shift gears.
FileDateTime will only give you the last date modified
KngEvrything, you don't have to worry about this thread no more, it's dated 11-24-1999 :rolleyes:.
doh, my bad, i guess i should look at that before posting again. :p
:p I did write this back to 1~2 monhs time for someone in this forum. Hope it useful for you.
2B Continue...Code:'//Put this code under a Form
Option Explicit
Private Sub CmdAction_Click()
If optMode(0).Value Then
lblInfo.Caption = GetFileDateTime(txtFile.Text, icCreated)
ElseIf optMode(1).Value Then
lblInfo.Caption = GetFileDateTime(txtFile.Text, icAccessed)
ElseIf optMode(2).Value Then
lblInfo.Caption = GetFileDateTime(txtFile.Text, icModified)
End If
End Sub
Private Sub CmdPath_Click()
On Error GoTo ErrHandle
With CDlg
.DialogTitle = "Open File..."
.ShowOpen
txtFile.Text = .FileName
End With
Exit Sub
ErrHandle:
txtFile.Text = ""
End Sub
'Code improved by vBulletin Tool (Save as...)
Continue previous post...
2B Continue...Code:'//Put this code under a Basic Module
Option Explicit
'//**********************************************************************
'//This is the Sample Code use to retrieve the given file date time value
'// Author : Chris.C
'// Date : 10, March 2001
'// Email : [email protected]
'// URl : http://go.to/chriscode
'//**********************************************************************
'//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
Public Enum fDatTime
icCreated = 0
icAccessed = 1
icModified = 2
End Enum
Last page... :D
enclosed sample project..Code:Public Function GetFileDateTime(ByVal lpFilename As String, ByVal mode As Integer) As String
If Len(lpFilename) = 0 Then
GetFileDateTime = ""
Exit Function
End If
'//open the file
hFile = CreateFile(lpFilename, _
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
Select Case mode
Case 0 '//Create
FileTimeToSystemTime ft_create, st
GetFileDateTime = Format(Str$(st.wDay) & "/" & Trim(Str$(st.wMonth)) & "/" & Trim(Str$(st.wYear)), "dd/mm/yyyy") & " " & Format(CInt(Trim(Str$(st.wHour))) - (tz.Bias / 60) & ":" & Trim(Str$(st.wMinute)) & ":" & Trim(Str$(st.wSecond)), "hh:nn:ss AMPM")
Case 1 '//Last Access
FileTimeToSystemTime ft_last_access, st
GetFileDateTime = Format(Str$(st.wDay) & "/" & Trim(Str$(st.wMonth)) & "/" & Trim(Str$(st.wYear)), "dd/mm/yyyy") & " " & Format(CInt(Trim(Str$(st.wHour))) - (tz.Bias / 60) & ":" & Trim(Str$(st.wMinute)) & ":" & Trim(Str$(st.wSecond)), "hh:nn:ss AMPM")
Case 2 '//Last Write
FileTimeToSystemTime ft_last_write, st
GetFileDateTime = Format(Str$(st.wDay) & "/" & Trim(Str$(st.wMonth)) & "/" & Trim(Str$(st.wYear)), "dd/mm/yyyy") & " " & Format(CInt(Trim(Str$(st.wHour))) - (tz.Bias / 60) & ":" & Trim(Str$(st.wMinute)) & ":" & Trim(Str$(st.wSecond)), "hh:nn:ss AMPM")
End Select
Else
GetFileDateTime = ""
End If
'//Close the file handle
CloseHandle hFile
End Function
'Code improved by vBulletin Tool (Save as...)