2

I am trying to get the created date and time of a particular file and then format it from 4/9/2016 to 040916. I end up with the result of 56DD16. I am not entirely sure where this value is coming from. I have used this method to format dates before without any problem. The code is below:

FileInfo fi = new FileInfo(Path.Combine(r.getCompanyFilesLocation(), r.getNyseFileName())); DateTime dateCreated = fi.CreationTime; string archiveFileName = dateCreated.ToString("mmDDyy"); 
1

3 Answers 3

3

You are using incorrect format string,mm Represent the Minute and there is nothing for DD, dd stands for day. so Change your formatString as MMddyy. to get the expected output. Here you can find more formatting options

string archiveFileName = dateCreated.ToString("MMddyy"); 
Sign up to request clarification or add additional context in comments.

Comments

2

.ToString("mmDDyy") is incorrect. The format should be .ToString("MMddyy")

You can always review the Custom Date and Time Format Strings.

Comments

0

You were using wrong format. Use this one and you will get the exact same output you required:

DateTime dateCreated = fi.CreationTime; string archiveFileName = dateCreated.ToString("MMddyy", CultureInfo.InvariantCulture); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.