Doubt Date

  • Thread starter Thread starter Paulo
  • Start date Start date
P

Paulo

Hi, how can I return just the date from a DateTime field ? Any C# .net 2.0 /
SQL function?

Thanks a lot!
 
Hi, how can I return just the date from a DateTime field ? Any C# .net 2.0
/ SQL function?

string strDateOnly = DateTime.Now.ToString("dd MMM yyyy");
 
But where do I put the reader['FieldName'] returned from the SQL Server ?

You made no mention of a datareader in your original post...

Please explain exactly what you are trying to do...
 
Sorry my friend, what I need to do is return a DateTime field from SQL
Server 2000 and put it on a text box to the user edit, but when I do:

Text.text = reader['SomeField'].AsString;

shows: 06/08/2007 00:00:00

I need only: 06/08/2007 (dd/mm/aaaa) the Brasil format...

Can you understand me ?

Thanks


Mark Rae said:
But where do I put the reader['FieldName'] returned from the SQL Server ?

You made no mention of a datareader in your original post...

Please explain exactly what you are trying to do...
 
Sorry my friend, what I need to do is return a DateTime field from SQL
Server 2000 and put it on a text box to the user edit, but when I do:

Text.text = reader['SomeField'].AsString;

shows: 06/08/2007 00:00:00

I need only: 06/08/2007 (dd/mm/aaaa) the Brasil format...

Text.text = reader['SomeField'].ToString("dd/mm/aaaa");
 
Error 2 No overload for method 'ToString' takes '1' arguments C:\Documents
and Settings\SUPORTE\Meus documentos\Visual Studio
2005\WebSites\WebSite6\Produto.aspx.cs 275 39 C:\...\WebSite6\


Mark Rae said:
Sorry my friend, what I need to do is return a DateTime field from SQL
Server 2000 and put it on a text box to the user edit, but when I do:

Text.text = reader['SomeField'].AsString;

shows: 06/08/2007 00:00:00

I need only: 06/08/2007 (dd/mm/aaaa) the Brasil format...

Text.text = reader['SomeField'].ToString("dd/mm/aaaa");
 
String.Format() should work

or load into a DateTime object and use dateTime.ToShortDateString().

The String format is useful if you are dealing with one date format. The
DateTime is better if you have to be culture aware, as it respects the
culture of the thread.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
 
You got to cast ot DateTime first
Text.text = ((DateTime)reader['SomeField']).ToString("dd/mm/aaaa");

George


Paulo said:
Error 2 No overload for method 'ToString' takes '1' arguments C:\Documents
and Settings\SUPORTE\Meus documentos\Visual Studio
2005\WebSites\WebSite6\Produto.aspx.cs 275 39 C:\...\WebSite6\


Mark Rae said:
Sorry my friend, what I need to do is return a DateTime field from SQL
Server 2000 and put it on a text box to the user edit, but when I do:

Text.text = reader['SomeField'].AsString;

shows: 06/08/2007 00:00:00

I need only: 06/08/2007 (dd/mm/aaaa) the Brasil format...

Text.text = reader['SomeField'].ToString("dd/mm/aaaa");
 
Back
Top