DateTime conversion for file name

Hello all - I would like to format my output file name with the current DateTime in a numeric expression.

I currently have :

fileName$ = "C:\tmp" & “Retirement_Portal” & “.txt”

I’d like to replace “Retirement_Portal” with the current DateTime using a numeric value.

Can this be done?

Thanks

Subject: DateTime conversion for file name

Use notesdatetime to get the date and time,then using left$, right$, etc., get the time.

Example:

Key is appended to your c://tmp value

Dim dateTime As New NotesDateTime(“”)

dateTime.LSLocalTime = Now

x = dateTime.DateOnly

tmp = Left$(x,2)

tmp2 = Right$(x,1)

tmp3 = Right$(x,7)

tmp4 = Left$(tmp3,2)



Key = tmp2 + tmp + tmp4 + "1"

Subject: RE: DateTime conversion for file name

or you could use way less code and go:

strFileName = "c:\tmp" & Format(Now(), “ddmmyyyy”) & “.txt”

Subject: RE: DateTime conversion for file name

Or even less if you want the date as well:strFileName = "c:\tmp" & Cstr(Now) & “.txt”

Subject: cstr() is very dangerous

Cstr() is such a nice-looking innocent function. An easy way to get a string representation of a date. The atom bomb hidden inside it is that the format of the date is determined by the regional settings on the computer running it. That means that its output is unpredictable. We have clients in several countries and usage of this function has caused us and our clients untold grief tracking down “it works on all the computers except for this one” type problems. Of course we cannot recreate said problem because all of our computers have the same regional settings.

This is not a problem for many developers but it should definitely always be in the back of your mind. In our shop we have banned the use of Cstr() and must use Format() instead because you have control over the format of the result. In this example, what if the regional settings of the computer resulted in a date string that violates file naming rules?

I am not being nitpicky but hopefully this post can save someone else the hair-pulling and aggravation that we have been through in our dance with the Cstr() function.

Subject: RE: cstr() is very dangerous

Thanks for posting the information regarding Cstr(). I would think you would run into the same problem with the format statement if you passed an invalid date to it.

You never use Cstr? What about for a simple convert for programming purposes?

Dim TmpNumber as Double ’ where FieldName is defined as number

Dim sTmpNumber as string

TmpNumber = Doc.FieldName(0)

sTmpNumber = Cstr(TmpNumber)

Do you see any problems with the use of cstr in this case?

Subject: RE: cstr() is very dangerous

Sorry, should have been clearer - we are not allowed to use Cstr() for date handling, otherwise it is fine.

Subject: DateTime conversion for file name

Thank you all very much!I’m all about less key strokes.

Subject: DateTime conversion for file name

I wound up doing this…

fileName$ = “C:\tmp" & Format(Now(), “mmddyyyy”) & Format(Time(), “hhmmss”) &”.txt"

Thanks again guys!