I need to create a file that has today's date in the file name. How can I get the date just as 20111110
and no slashes?
It is therefore preferable to write the name of the month. When writing the date by numbers only, one can separate them by using a hyphen (-), a slash (/), or a dot (.): 05-07-2013, or 05/07/2013, or 05.07. 2013. Omitting the initial zero in the numbers smaller than 10 is also accepted: 5-7-2013, 5/7/2013, or 5.7.
1. Select the date cells you will remove the dashes, slashes, or hyphens from, right click, and select Format Cells from the context menu. 2. In the Format Cells dialog, under the Number tab, click to activate Custom in the Category list box, type the date code mmddyyyy into the Type box, and click the OK button.
[char1 char2] is the regex used to replace two characters with a single character. We can use [_/] to replace all the underscores and slashes with a dash.
DateTime.Now.ToString("yyyyMMdd")
Also, you may not be be aware of System.IO.Path.Combine
. It makes building paths a little cleaner and more foolproof.
Simply use a custom datetime format string.
myDate.ToString("yyyyMMdd");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With