Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output Date Without Slashes

Tags:

c#

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?

like image 917
xbonez Avatar asked Nov 11 '10 20:11

xbonez


People also ask

How do you write dates without 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.

How do I convert a date in Excel without slashes?

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.

What function could you use to replace slashes for dashes in a list of dates?

[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.


2 Answers

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.

like image 126
D'Arcy Rittich Avatar answered Sep 27 '22 21:09

D'Arcy Rittich


Simply use a custom datetime format string.

myDate.ToString("yyyyMMdd");
like image 24
Oded Avatar answered Sep 27 '22 22:09

Oded