Generating filename using date (1 Viewer)

ssh

Registered User.
Local time
Today, 03:26
Joined
May 22, 2002
Messages
49
How to generate a filename that uses date values? For example, date value is November 21, 1999 and filename should be 21-11-99. Problem was how to separate date parts. Thanks
 

ColinEssex

Old registered user
Local time
Today, 03:26
Joined
Feb 22, 2002
Messages
9,155
Won't you get files with the same filename if there are more than one for a certain date?

Col
:cool:
 

Mile-O

Back once again...
Local time
Today, 03:26
Joined
Dec 10, 2002
Messages
11,316
Dim strFileName As String

strFileName = Day(txtDate) & "-" & Month(txtDate) & "-" & Year(txtDate)
 

ssh

Registered User.
Local time
Today, 03:26
Joined
May 22, 2002
Messages
49
Towards the right way but I want 99 instead of 1999.
 

Mile-O

Back once again...
Local time
Today, 03:26
Joined
Dec 10, 2002
Messages
11,316
strFileName = Day(txtDate) & "-" & Month(txtDate) & "-" & Right(Year(txtDate),2)


Also, to add a 0 to the front of a month or day that is a single figure you could try this:

PHP:
Dim strFileName As String
    
    If Day(txtDate) < 10 Then
        strFileName = "0" & Day(txtDate) & "-"
    Else
        strFileName = Day(txtDate) & "-"
    End If
    If Month(txtDate) < 10 Then
        strFileName = strFileName & "0" & Month(txtDate) & "-"
    Else
        strFileName = strFileName & Month(txtDate) & "-"
    End If
    strFileName = strFileName & right(Year(txtDate), 2)


I tried to do this line but it didn't work:

strFileName = Format(Day(txtDate),"dd") & "-" & Format(Month(txtDate) ,"mm") & "-" & Format(Year(txtDate),"yy")

When I tried that way the string returned was something like 08-04-1905 which I thought was rather bizarre.
 
Last edited:

ssh

Registered User.
Local time
Today, 03:26
Joined
May 22, 2002
Messages
49
I'll give a try, and let you know.
 

Pat Hartman

Super Moderator
Staff member
Local time
, 22:26
Joined
Feb 19, 2002
Messages
43,603
You can simplify to:

Format(YourDate,"mm-dd-yy")

08-04-1905 was not bizzare at all. The following statement is incorrect because, the format()"s are not being passed the date that you think you are passing. Format(YourDate,"mm") calculates the month portion of the date represented by YourDate. As I have mentioned dozens of times here (and others have as well), dates are NOT stored as text strings. They are stored as double precision numbers. The integer portion of the number represents the number of days since Dec 30, 1899 and the decimal portion represents the time of day. If you extract the month prior and pass that value to the Format() function as in Format(Month(YourDate),"mm") what you are doing is substituting some number between 1 and 12 for the actual serial number that your date represents. Today (Jan 7, 2003) is 37628. To prove this to yourself open the immediate window and type:
print cdate(37628)
print cdate(1)
print cdate(-3)
and observe the dates that are printed.
 

ssh

Registered User.
Local time
Today, 03:26
Joined
May 22, 2002
Messages
49
Format(YourDate,"mm-dd-yy") worked. Love simple things!
 

Users who are viewing this thread

Top Bottom