How to add the date and time in my end of day report file?

That will result in…

EODReport.xlsx\20220826

You don’t use Path.Combine to build the filename. You use it to combine the final filename with the rest of the path. So you need an assign to set the filename:

myfile = “EODReport” + Now.ToString(“MMddyyyy”) + “.xlsx”

Then…

Path.Combine(somePathVar,myfile)

to get something like…

C:\temp\EODReport08262022.xlsx

The point to Path.Combine is to make sure the \ are added correctly. Consider you have the following variables:

myPath = “C:\temp”
myFile = “somefile.xlsx”

If you just do myPath + myFile you end up with…

C:\tempsomefile.xlsx

But Path.Combine(myPath,myFile) avoids that and gives you the correct “C:\temp\somefile.xlsx”

It’s very useful when you need to combine multiple things into a path, like…

Path.Combine(“C:\Users”,Environment.Username,“Downloads”)

That’ll give you the correct path of "C:\Users\JDOE\Downloads"

2 Likes