VBA Date character extraction

Hi

I want to include the date and time of file generation in the file name. How can I keep the mm, dd, yy, hh, mm, ss and delete the characters  / and : from the general format mm/dd/yy hh:mm:ss ?


Thanks,
st
spacetravellerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
Format(YourDateGoesHere, "mm") & Format(YourDateGoesHere, "dd" & Format(YourDateGoesHere, "yy") & etc. etc.
0
 
stevbeConnect With a Mentor Commented:
Public Function MakeFileName(FileName As String, FileExt As String)
    MakeFileName = FileName & Format(Now(), "mmddyyhhnnss") & FileExt
End Funcrion

0
 
stevbeCommented:
the key part is to not use the seperators in the Format Funtrion ...

Format(Now(), "mmddyyhhnnss")

now add your base filename at the beginning and file extention at the end ... the function I posted makes this a bit easier for me as I have a number of file formats I export to.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Wowwie.  Learn something new every day.
0
 
stevbeCommented:
I use yyyymmddhhnnss so I can easily sort my files cronologically but that is just me ... format it however you would like :-)
0
 
spacetravellerAuthor Commented:
Thanks Jim Horn and Stevbe. now I know that I have to use "Format".

Thanks a lot.

st
0
All Courses

From novice to tech pro — start learning today.