Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Howto build a Select filter with DateTime
Message
De
24/09/2007 16:01:00
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
24/09/2007 12:16:23
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Divers
Thread ID:
01256085
Message ID:
01256464
Vues:
17
>>>>>Hi,
>>>>>
>>>>>I'm trying to construct a DataTable.Select filter expression based on a DateTime comparison. Something like:
>>>>>string ds = DateTime.Now.ToString();
>>>>>string s = "BackupType=1 AND BackupFinishDate < Convert('" + ds + "','System.DateTime')";
>>>>>DataRow[] drs = dt.Select(s, "BackupFinishDate DESC");
>>>>>The Select gives a FormatException with "String was not recognized as a valid DateTime".
>>>>>The resulting s in the select looks like this:
>>>>>"BackupType=1 AND BackupFinishDate < Convert('22/09/2007 17:02:31','System.DateTime')"
>>>>>
>>>>>How do I get this to work?
>>>>>TIA,
>>>>>Viv
>>>>
>>>>Viv,
>>>>No need for a convert.
>>>>
>>>>
>>>>string s = String.Format(
>>>>   "BackupType=1 AND BackupFinishDate < '{0}'",
>>>>   DateTime.Now.ToString("u")
>>>>   );
>>>>
>>>>PS: ToString() would work too. I like to use universal formats.
>>>
>>>Hi,
>>>Well ToString() doesn't work (same error). ToString("u") avoids the error (but, as is, returns the wrong results because there's no time zone conversion). ToString("s") seems to be the answer ?
>>>Thx,
>>>Viv
>>
>>Maybe, or convert to ToUniversalTime() first?
>
>t.ToUniversalTime().ToString("u") and t.ToString("s") both work. So do you see any benefit in using the former?
>Regards,
>Viv

Depending on your data I think you'd give the best answer:)
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
Répondre
Fil
Voir

Click here to load this message in the networking platform