Display TimeStamp / DateTime as yyyyMMddHHMMSS string in .Net use as Filename.

It would be a good idea to put a timestamp onto a filename, if your application/process that export a file or generate a file for user to download.
E.g.
Filename_YearMonthDaysHourMinuteSecond.txt
yyyyMMddhhmmss
Example_20100123123456.txt

It is quite simple to use .Net to generate a TimeStamp as a string.
Here it is the solution:

VB
String.Format(“{0:yyyyMMddhhmmss}”, Today.Now)

C# [which is very similar as VB]
string.Format(“{0:yyyyMMddhhmmss}”, DateTime.Now)

Hope you find it useful =)

Leave a Reply