Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Something wrong with how I'm using Substring()?
Message
De
12/01/2007 05:35:38
Alexandre Palma
Harms Software, Inc.
Alverca, Portugal
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01184772
Message ID:
01184943
Vues:
14
>>Hello.
>>
>>I'm getting an error on the last line of the code below "ArgumentOutOfRangeException Make sure all arguments to this method have valid values as defined by the invoked method...."
>>
>>
>>
>>int nYear = DateTime.Now.Year;
>>int nDay = DateTime.Now.Day;
>>int nMonth = DateTime.Now.Month;
>>string cKey = nMonth.ToString().PadLeft(2, '0');
>>cKey += nDay.ToString().PadLeft(2, '0');
>>cKey += nYear.ToString().Substring(3, 2);
>>
>>
>>
>>What am I doing wrong?
>>
>>TIA.
>
>
>DateTime now = DateTime.Now;
>string cKey = string.Format("{0}{1}{2}", now.Month.ToString().PadLeft(2, '0'), now.Day.ToString().PadLeft(2, '0'), now.Year.ToString().Substring(2, 2));
>
Or even better
string cKey = DateTime.Now.ToString("ddMMyy");
Alexandre Palma
Senior Application Architect
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform