Home > Archive > Visual Basic Syntax > April 2005 > creating function "GetDate"
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
creating function "GetDate"
|
|
| Barbara 2005-04-19, 4:03 pm |
| I have created a function called "GetDate" Here is my code that I am
working with...
Private Function GetDate() As String
Select Case Month(Now)
Case 10
GetDate = "0" & Format(date, "dd")
Case 11
GetDate = "A" & Format(date, "dd")
Case 12
GetDate = "B" & Format(date, "dd")
Case Else
GetDate = CStr(Month(Now)) & Format(date, "dd")
End Select
The above code does work fine; however I need to have the "Now" record the
filename.DateLastModified vs. Current system date and I have not been able
to get the right syntax to do this.
Can anyone help me with this? Thanks in advance Barbara
| |
| Rick Rothstein 2005-04-19, 4:03 pm |
| > I have created a function called "GetDate" Here is my code that I am
> working with...
>
> Private Function GetDate() As String
> Select Case Month(Now)
> Case 10
> GetDate = "0" & Format(date, "dd")
> Case 11
> GetDate = "A" & Format(date, "dd")
> Case 12
> GetDate = "B" & Format(date, "dd")
> Case Else
> GetDate = CStr(Month(Now)) & Format(date, "dd")
> End Select
This function could be "simplified" a little bit as follows
Private Function GetDate() As String
Const ENCODED_MONTHS As String = "1234567890AB"
GetDate = Mid$(ENCODED_MONTHS, Month(Now), 1) & Format(Date, "dd")
End Fucntion
> The above code does work fine; however I need to have the "Now" record
the
> filename.DateLastModified vs. Current system date and I have not been
able
> to get the right syntax to do this.
> Can anyone help me with this? Thanks in advance Barbara
What is "filename.DateLastModified"? If it is from one of the VB.NET
versions, then you are in the wrong newsgroup (as this one caters to
versions of VB from 1 to 6). If it is from FSO, you don't need that call
as VB has a built-in function for obtaining the last modified date...
FileDateTime. You would use it in your (or my variation of your)
function by replacing Month(Now) with this
Month(FileDateTime("c:\directory1\directory2\yourfilename.ext")
where you specify the path and file name where I have shown generic
placeholders.
Rick - MVP
| |
| Rick Rothstein 2005-04-19, 4:03 pm |
| > Month(FileDateTime("c:\directory1\directory2\yourfilename.ext")
Whoops! I left off a trailing parenthesis...
Month(FileDateTime("c:\directory1\directory2\yourfilename.ext"))
Rick - MVP
| |
| Bob Butler 2005-04-19, 4:03 pm |
| "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:%23$YpA1ORFHA.1528@TK2MSFTNGP09.phx.gbl
> What is "filename.DateLastModified"? If it is from one of the VB.NET
> versions, then you are in the wrong newsgroup (as this one caters to
> versions of VB from 1 to 6). If it is from FSO, you don't need that
> call as VB has a built-in function for obtaining the last modified
> date... FileDateTime. You would use it in your (or my variation of
> your) function by replacing Month(Now) with this
>
> Month(FileDateTime("c:\directory1\directory2\yourfilename.ext")
>
> where you specify the path and file name where I have shown generic
> placeholders.
The call to "Date" would also need to be replaced...
Private Function GetDate(ByVal FilePath As String) As String
Const ENCODED_MONTHS As String = "1234567890AB"
Dim d As Date
d=FileDateTime(FilePath)
GetDate = Mid$(ENCODED_MONTHS, Month(d), 1) & Format$(d, "dd")
End Function
and call it like:
sDate=GetDate("c:\directory1\directory2\yourfilename.ext")
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
| |
| Rick Rothstein 2005-04-19, 4:03 pm |
| > > What is "filename.DateLastModified"? If it is from one of the VB.NET
>
> The call to "Date" would also need to be replaced...
Yes, of course, you are right. I tested the routine quickly and then
copied it to my response without the Format "dd" section. When I
realized I omitted that (during OE's spell check), I simply copied that
section from the original message without thinking twice about it.
Thanks for catching it.
Rick
|
|
|
|
|