Results 1 to 4 of 4

Thread: Date

  1. #1

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Anyone know how to easily change that stupid int of date and time of the DATE type to a normal looking string?
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  2. #2

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Incase any one cares here is what you can do

    PHP Code:
    DATE d 36957.5638888889// 03/07/2001  01:32:00 PMb    
    FILETIME ft = {00};
    SYSTEMTIME st = {189912030000}; // 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); 
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Technocrat, hope this will help. Although it is in VB.

    Code:
    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

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Continue previous post...

    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width