Doubt Date

Discussion in 'ASP .Net' started by Paulo, Aug 7, 2007.

  1. Paulo

    Paulo Guest

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

    Thanks a lot!
     
    Paulo, Aug 7, 2007
    #1
    1. Advertising

  2. "Paulo" <> wrote in message
    news:...

    > 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
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Aug 7, 2007
    #2
    1. Advertising

  3. Paulo

    Paulo Guest

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

    "Mark Rae [MVP]" <> escreveu na mensagem
    news:...
    > "Paulo" <> wrote in message
    > news:...
    >
    >> 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
    > ASP.NET MVP
    > http://www.markrae.net
     
    Paulo, Aug 7, 2007
    #3
  4. "Paulo" <> wrote in message
    news:%23f%23%...

    > 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
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Aug 7, 2007
    #4
  5. Paulo

    Paulo Guest

    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 [MVP]" <> escreveu na mensagem
    news:...
    > "Paulo" <> wrote in message
    > news:%23f%23%...
    >
    >> 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
    > ASP.NET MVP
    > http://www.markrae.net
     
    Paulo, Aug 7, 2007
    #5
  6. "Paulo" <> wrote in message
    news:...

    > 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");


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Aug 7, 2007
    #6
  7. Paulo

    Paulo Guest

    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 [MVP]" <> escreveu na mensagem
    news:...
    > "Paulo" <> wrote in message
    > news:...
    >
    >> 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");
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    Paulo, Aug 7, 2007
    #7
  8. 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!
    ************************************************
    "Paulo" <> wrote in message
    news:...
    > Hi, how can I return just the date from a DateTime field ? Any C# .net 2.0
    > / SQL function?
    >
    > Thanks a lot!
    >
     
    Cowboy \(Gregory A. Beamer\), Aug 7, 2007
    #8
  9. You got to cast ot DateTime first
    Text.text = ((DateTime)reader['SomeField']).ToString("dd/mm/aaaa");

    George


    "Paulo" <> wrote in message
    news:...
    > 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 [MVP]" <> escreveu na mensagem
    > news:...
    >> "Paulo" <> wrote in message
    >> news:...
    >>
    >>> 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");
    >>
    >>
    >> --
    >> Mark Rae
    >> ASP.NET MVP
    >> http://www.markrae.net

    >
    >
     
    George Ter-Saakov, Aug 7, 2007
    #9
  10. "George Ter-Saakov" <> wrote in message
    news:%...

    > You got to cast ot DateTime first
    > Text.text = ((DateTime)reader['SomeField']).ToString("dd/mm/aaaa");


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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Aug 7, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,332
    Michael Borgwardt
    May 30, 2004
  2. Bob Nelson

    doubt about doubt

    Bob Nelson, Jul 28, 2006, in forum: C Programming
    Replies:
    11
    Views:
    650
  3. Replies:
    0
    Views:
    589
  4. Peter Otten
    Replies:
    2
    Views:
    134
    Cousin Stanley
    Aug 10, 2013
  5. Terry Reedy
    Replies:
    0
    Views:
    125
    Terry Reedy
    Aug 10, 2013
Loading...

Share This Page