Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Datetimeconverter
Message
De
11/07/2008 05:00:09
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 2.0
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01330393
Message ID:
01330461
Vues:
23
This message has been marked as the solution to the initial question of the thread.
>I would like to convert a date string to a datetime value. I found a thread on doing that using DateTime.TryParse and that works fine. However, I would like to know why I can't get the datetimeconverter to work. Here's what I tried. I always ended up with a date time value of 1/1/0001. Although I have shown hard-coded strings here, in my test, I was using strings passed as parameters and used paramstring.ToString() for the string value, if that makes any difference. Thanks.
>
>
>            DateTime dtBegDate;
>            DateTime dtEndDate;
>            string dstrBegDate = '1/1/2006';
>            string dstrEndDate = '12/31/2006';
>            TypeDescriptor.GetConverter(dtBegDate).ConvertFrom(dstrBegDate);
>            TypeDescriptor.GetConverter(dtEndDate).ConvertFrom(dstrEndDate);
>
This works for me (current culture EN-US):
            DateTime dtBegDate;
            DateTime dtEndDate;
            string dstrBegDate = "1/1/2006";
            string dstrEndDate = "12/31/2006";
            dtBegDate = (DateTime)TypeDescriptor.GetConverter(typeof(DateTime)).ConvertFrom(dstrBegDate);
            dtEndDate = (DateTime)TypeDescriptor.GetConverter(typeof(DateTime)).ConvertFrom(dstrEndDate);
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform