Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Doubt Date

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paulo - 07 Aug 2007 12:29 GMT
Hi, how can I return just the date from a DateTime field ? Any C# .net 2.0 /
SQL function?

Thanks a lot!
Mark Rae [MVP] - 07 Aug 2007 12:47 GMT
> 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");

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Paulo - 07 Aug 2007 13:05 GMT
But where do I put the reader['FieldName'] returned from the SQL Server ?

>> 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");
Mark Rae [MVP] - 07 Aug 2007 13:16 GMT
> 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...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Paulo - 07 Aug 2007 13:22 GMT
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

>> 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...
Mark Rae [MVP] - 07 Aug 2007 13:47 GMT
> 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:
[quoted text clipped - 4 lines]
>
> I need only: 06/08/2007 (dd/mm/aaaa) the Brasil format...

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

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Paulo - 07 Aug 2007 14:04 GMT
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\

>> 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:
[quoted text clipped - 6 lines]
>
> Text.text = reader['SomeField'].ToString("dd/mm/aaaa");
George Ter-Saakov - 07 Aug 2007 15:26 GMT
You got to cast ot DateTime first
Text.text = ((DateTime)reader['SomeField']).ToString("dd/mm/aaaa");

George

> Error 2 No overload for method 'ToString' takes '1' arguments C:\Documents
> and Settings\SUPORTE\Meus documentos\Visual Studio
[quoted text clipped - 10 lines]
>>
>> Text.text = reader['SomeField'].ToString("dd/mm/aaaa");
Mark Rae [MVP] - 07 Aug 2007 16:38 GMT
> You got to cast ot DateTime first
> Text.text = ((DateTime)reader['SomeField']).ToString("dd/mm/aaaa");

D'oh! Apologies, everybody... :-(

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Cowboy (Gregory A. Beamer) - 07 Aug 2007 14:18 GMT
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.

Signature

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!
************************************************

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.