Date sting formatting, the easy way.
-
string dateStr = DateTime.Now.Day.ToString("00") + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString();
string timeStr = DateTime.Now.TimeOfDay.Hours.ToString("00") + DateTime.Now.TimeOfDay.Minutes.ToString("00") + DateTime.Now.TimeOfDay.Seconds.ToString("00");
string path = FileOutputDir + GetProviderName() + "-Summary-" + dateStr + "-" + timeStr + ".csv";Another gem, from the gem of a project I've inherited. Now:
string path = string.Format("{0}{1}-Summary-{2}", FileOutputDir, GetProviderName(), DateTime.Now.ToString("ddMMyyyy-HHmmss") + ".csv");
[Edit] I've now just discovered the method containing this code never gets called. Its a good job wwe don't have any unit tests, or I'de have to remove those too..... :-)
CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
-
string dateStr = DateTime.Now.Day.ToString("00") + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString();
string timeStr = DateTime.Now.TimeOfDay.Hours.ToString("00") + DateTime.Now.TimeOfDay.Minutes.ToString("00") + DateTime.Now.TimeOfDay.Seconds.ToString("00");
string path = FileOutputDir + GetProviderName() + "-Summary-" + dateStr + "-" + timeStr + ".csv";Another gem, from the gem of a project I've inherited. Now:
string path = string.Format("{0}{1}-Summary-{2}", FileOutputDir, GetProviderName(), DateTime.Now.ToString("ddMMyyyy-HHmmss") + ".csv");
[Edit] I've now just discovered the method containing this code never gets called. Its a good job wwe don't have any unit tests, or I'de have to remove those too..... :-)
CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
-
string dateStr = DateTime.Now.Day.ToString("00") + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString();
string timeStr = DateTime.Now.TimeOfDay.Hours.ToString("00") + DateTime.Now.TimeOfDay.Minutes.ToString("00") + DateTime.Now.TimeOfDay.Seconds.ToString("00");
string path = FileOutputDir + GetProviderName() + "-Summary-" + dateStr + "-" + timeStr + ".csv";Another gem, from the gem of a project I've inherited. Now:
string path = string.Format("{0}{1}-Summary-{2}", FileOutputDir, GetProviderName(), DateTime.Now.ToString("ddMMyyyy-HHmmss") + ".csv");
[Edit] I've now just discovered the method containing this code never gets called. Its a good job wwe don't have any unit tests, or I'de have to remove those too..... :-)
CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
i get that a lot from ppl that "think" they know how to code... rather than taking the shorter quicker way to do it they take the longer, "Look at all the code ive wrote to look cool" way of doing it in the off chance it baffles with obsufacation...
View my CodePlex Projects here -> http://www.codeplex.com/site/users/view/john\_crocker
-
string dateStr = DateTime.Now.Day.ToString("00") + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString();
string timeStr = DateTime.Now.TimeOfDay.Hours.ToString("00") + DateTime.Now.TimeOfDay.Minutes.ToString("00") + DateTime.Now.TimeOfDay.Seconds.ToString("00");
string path = FileOutputDir + GetProviderName() + "-Summary-" + dateStr + "-" + timeStr + ".csv";Another gem, from the gem of a project I've inherited. Now:
string path = string.Format("{0}{1}-Summary-{2}", FileOutputDir, GetProviderName(), DateTime.Now.ToString("ddMMyyyy-HHmmss") + ".csv");
[Edit] I've now just discovered the method containing this code never gets called. Its a good job wwe don't have any unit tests, or I'de have to remove those too..... :-)
CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
string.Format("{0}{1}-Summary-{2:ddMMyyyy-HHmmss}.csv", ...
But please use an ISO 8601 compliant format: yyyyMMdd -
string.Format("{0}{1}-Summary-{2:ddMMyyyy-HHmmss}.csv", ...
But please use an ISO 8601 compliant format: yyyyMMddYep (& I should have spotted it :doh: ), except for the ISO 8061 bit, that's out of my hands...
CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
-
string dateStr = DateTime.Now.Day.ToString("00") + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString();
string timeStr = DateTime.Now.TimeOfDay.Hours.ToString("00") + DateTime.Now.TimeOfDay.Minutes.ToString("00") + DateTime.Now.TimeOfDay.Seconds.ToString("00");
string path = FileOutputDir + GetProviderName() + "-Summary-" + dateStr + "-" + timeStr + ".csv";Another gem, from the gem of a project I've inherited. Now:
string path = string.Format("{0}{1}-Summary-{2}", FileOutputDir, GetProviderName(), DateTime.Now.ToString("ddMMyyyy-HHmmss") + ".csv");
[Edit] I've now just discovered the method containing this code never gets called. Its a good job wwe don't have any unit tests, or I'de have to remove those too..... :-)
CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
OK I understand whats wrong with those:
string dateStr = DateTime.Now.Day.ToString("00") + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString();
string timeStr = DateTime.Now.TimeOfDay.Hours.ToString("00") + DateTime.Now.TimeOfDay.Minutes.ToString("00") + DateTime.Now.TimeOfDay.Seconds.ToString("00");I would have been easier to do: DateTime.Now.ToString("mmDDYYYY") or whatever the format string was. But I'm not quite sure what's wrong with these:
string path = FileOutputDir + GetProviderName() + "-Summary-" + dateStr + "-" + timeStr + ".csv";
string path = string.Format("{0}{1}-Summary-{2}", FileOutputDir, GetProviderName(), DateTime.Now.ToString("ddMMyyyy-HHmmss") + ".csv"); -
OK I understand whats wrong with those:
string dateStr = DateTime.Now.Day.ToString("00") + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString();
string timeStr = DateTime.Now.TimeOfDay.Hours.ToString("00") + DateTime.Now.TimeOfDay.Minutes.ToString("00") + DateTime.Now.TimeOfDay.Seconds.ToString("00");I would have been easier to do: DateTime.Now.ToString("mmDDYYYY") or whatever the format string was. But I'm not quite sure what's wrong with these:
string path = FileOutputDir + GetProviderName() + "-Summary-" + dateStr + "-" + timeStr + ".csv";
string path = string.Format("{0}{1}-Summary-{2}", FileOutputDir, GetProviderName(), DateTime.Now.ToString("ddMMyyyy-HHmmss") + ".csv");I think that the OP is saying that he replaced the first example block of code with the second. The first block is what it used to do; the second block is what it does now. Although, apparently it never gets called anyway so the whole thing is academic.
-
I think that the OP is saying that he replaced the first example block of code with the second. The first block is what it used to do; the second block is what it does now. Although, apparently it never gets called anyway so the whole thing is academic.
Exactly so!
CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
-
string dateStr = DateTime.Now.Day.ToString("00") + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString();
string timeStr = DateTime.Now.TimeOfDay.Hours.ToString("00") + DateTime.Now.TimeOfDay.Minutes.ToString("00") + DateTime.Now.TimeOfDay.Seconds.ToString("00");
string path = FileOutputDir + GetProviderName() + "-Summary-" + dateStr + "-" + timeStr + ".csv";Another gem, from the gem of a project I've inherited. Now:
string path = string.Format("{0}{1}-Summary-{2}", FileOutputDir, GetProviderName(), DateTime.Now.ToString("ddMMyyyy-HHmmss") + ".csv");
[Edit] I've now just discovered the method containing this code never gets called. Its a good job wwe don't have any unit tests, or I'de have to remove those too..... :-)
CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
That's nothing. Check this piece of pure art.
//returns a string representation of the date used to create //the logs file. The logs file are somethnig like '15\_09\_2009.log'. //a new log file is created each day if and ONLY if an error //apears while using the program that day. public static string GetStringDate(DateTime dt) { StringBuilder sb = new StringBuilder(); //Month int mnth = dt.Month; if (mnth < 10) { //leading zero sb.Append('0'); sb.Append(mnth); sb.Append('\_'); } else { sb.Append(mnth); sb.Append('\_'); } //day int day = dt.Day; if (day < 10) { //leading zero sb.Append('0'); sb.Append(day); sb.Append('\_'); } else { sb.Append(day); sb.Append('\_'); } //year sb.Append(dt.Year); //return the formated string return sb.ToString(); }
Among other spectacular utilities
-
That's nothing. Check this piece of pure art.
//returns a string representation of the date used to create //the logs file. The logs file are somethnig like '15\_09\_2009.log'. //a new log file is created each day if and ONLY if an error //apears while using the program that day. public static string GetStringDate(DateTime dt) { StringBuilder sb = new StringBuilder(); //Month int mnth = dt.Month; if (mnth < 10) { //leading zero sb.Append('0'); sb.Append(mnth); sb.Append('\_'); } else { sb.Append(mnth); sb.Append('\_'); } //day int day = dt.Day; if (day < 10) { //leading zero sb.Append('0'); sb.Append(day); sb.Append('\_'); } else { sb.Append(day); sb.Append('\_'); } //year sb.Append(dt.Year); //return the formated string return sb.ToString(); }
Among other spectacular utilities