Results 1 to 7 of 7

Thread: [RESOLVED] Local Date to DOS Date

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Resolved [RESOLVED] Local Date to DOS Date

    Hi does anyone now how I can say take a Date and Time such as 10/2/2006 10:10:00 AM and encoded it to the standard MS DOS format.

    The reason I need this is because I am working on some small compression program and the date for PKZip compatable files.

    I looked in the forums, code bank and the internet and Cannot seem to find anything what so ever.

    any help or code examples will be greatfull.

    Thanks
    When your dreams come true.
    On error resume pulling hair out.

  2. #2

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Local Date to DOS Date

    VB Code:
    1. Option Explicit
    2.  
    3. 'Dos Format: Fri 01/09/2006
    4.  
    5. Private Sub Form_Load()
    6.  
    7.     MsgBox Dos_Date_Format(#10/2/2006 10:10:00 AM#)
    8.     MsgBox Dos_Date_Format(Now)
    9.  
    10. End Sub
    11.  
    12. Private Function Dos_Date_Format(dteDate As Date) As String
    13. Dim strDay As String
    14.  
    15.     'Determin the day, and truncate it to 3 letters
    16.     strDay = Left$(WeekdayName(Weekday(dteDate, vbMonday)), 3)
    17.     'Join the truncated day and the date
    18.     Dos_Date_Format = strDay & " " & Format$(dteDate, "mm/dd/yyyy", vbMonday)
    19.  
    20. End Function
    Last edited by Bruce Fox; Aug 31st, 2006 at 04:40 PM.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Local Date to DOS Date

    well from what information I did find with was not very much it just talks about how it packed and then stored as a Long Int value. tho I duno how to pack it that what I need to figure out.
    When your dreams come true.
    On error resume pulling hair out.

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Local Date to DOS Date

    I assumed that you required the format that is presented when you enter "Date" in the command promt.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Local Date to DOS Date

    No I need the long value returned form a local date but thanks for the code anyway might be usfull for something else

    Below I left the code that will unpack the long Date and Time value what I need to know is how to put pack the date and time to make a long value

    Code:
    Private Function SHR(iByte As Long, iShift As Long) As Long
        'Shift right
        SHR = (iByte \ (2 ^ iShift))
    End Function
    
    Private Sub Command1_Click()
    Dim DateTimeVal As Long
    Dim iDate As Date
    Dim iTime As Date
    
        DateTimeVal = 752685168 'This long value has date and time
        'Last Update Date
        iDate = DateSerial((SHR(DateTimeVal, 25) And &H7F) + 1980, _
        (SHR(DateTimeVal, 21) And &HF), _
        SHR(DateTimeVal, 16) And &H1F)
        'Last Update Time
        iTime = TimeSerial((SHR(DateTimeVal, 11) And &H1F), _
        (SHR(DateTimeVal, 5) And &H3F), _
        SHR(DateTimeVal, 16) And &H1F)
        MsgBox iDate & "--" & iTime
    End Sub
    Last edited by dreamvb; Aug 31st, 2006 at 06:10 PM.
    When your dreams come true.
    On error resume pulling hair out.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Local Date to DOS Date

    Has anyone else got some ideas that may help. I tryed looking on the net agian and still can;t seem to find much of anything. I know you guys are busy with your own projects but I really need to sort this out.

    Thanks.
    Last edited by dreamvb; Sep 1st, 2006 at 10:10 AM.
    When your dreams come true.
    On error resume pulling hair out.

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