Generate filename based on current date & time.
Posted: Fri Sep 25, 2015 2:43 pm
This little snippet generates a filename based on the current date and time. Can be useful for apps that save series of files, like an image saver, or text saving program. An example is:: 2015-08-01-09-12-50.txt
I use it for a notepad app (that's why I added .txt to the end of filename). Maybe someone can use it.
- Dav
I use it for a notepad app (that's why I added .txt to the end of filename). Maybe someone can use it.
- Dav
Code: Select all
'datefilename.txt
'generates a filename based on date & time
'example: 2015-08-01-09-12-50.txt
'by Dav
print datename$
end
def datename$()
'make a name based on date & time
'example: 2015-08-01-09-12-50.txt
fd$=current_year()&"-"
fd$=fd$&pad$(str$(current_month()))&"-"
fd$=fd$&pad$(str$(current_date()))&"-"
fd$=fd$&pad$(str$(current_hour()))&"-"
fd$=fd$&pad$(str$(current_minute()))&"-"
fd$=fd$&pad$(str$(current_second()))&".txt"
datename$=fd$
end def
def pad$(a$)
'adds leading 0 to string if len=1
if len(a$)=1 then pad$="0"&a$ else pad$=a$
end def