[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
Re: Local Date to DOS Date
What is the standard MS DOS format for date and time?
Re: Local Date to DOS Date
VB Code:
Option Explicit
'Dos Format: Fri 01/09/2006
Private Sub Form_Load()
MsgBox Dos_Date_Format(#10/2/2006 10:10:00 AM#)
MsgBox Dos_Date_Format(Now)
End Sub
Private Function Dos_Date_Format(dteDate As Date) As String
Dim strDay As String
'Determin the day, and truncate it to 3 letters
strDay = Left$(WeekdayName(Weekday(dteDate, vbMonday)), 3)
'Join the truncated day and the date
Dos_Date_Format = strDay & " " & Format$(dteDate, "mm/dd/yyyy", vbMonday)
End Function
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.
Re: Local Date to DOS Date
I assumed that you required the format that is presented when you enter "Date" in the command promt.
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
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.