Date Formats of Date in Database

Discussion in 'ASP .Net' started by Martin Eyles, Mar 28, 2006.

  1. Martin Eyles

    Martin Eyles Guest

    Hi,
    I am trying to extract a date from a database, and display it in
    yyyy-mm-dd hh:mm:ss format on an ASP.NET webpage. I have been using the CStr
    function to turn this into text, but this doesn't give me enough control to
    get the right date format. Can anyone suggest a solution?

    Thanks,
    Martin


    'Snippet of Code I Tried
    SQL = ("SELECT " & aDateTime)
    anSQLCommand = New System.Data.SqlClient.SqlCommand
    anSQLCommand.Connection() = conn
    anSQLCommand.CommandText = SQL
    R = anSQLCommand.ExecuteReader
    While R.Read
    displayADateTime = CStr(R(0))
    End While
     
    Martin Eyles, Mar 28, 2006
    #1
    1. Advertising

  2. Martin Eyles

    Maarten Guest

    R(0).ToString("yyyy-mm-dd")

    "Martin Eyles" <> wrote in message
    news:...
    > Hi,
    > I am trying to extract a date from a database, and display it in
    > yyyy-mm-dd hh:mm:ss format on an ASP.NET webpage. I have been using the
    > CStr function to turn this into text, but this doesn't give me enough
    > control to get the right date format. Can anyone suggest a solution?
    >
    > Thanks,
    > Martin
    >
    >
    > 'Snippet of Code I Tried
    > SQL = ("SELECT " & aDateTime)
    > anSQLCommand = New System.Data.SqlClient.SqlCommand
    > anSQLCommand.Connection() = conn
    > anSQLCommand.CommandText = SQL
    > R = anSQLCommand.ExecuteReader
    > While R.Read
    > displayADateTime = CStr(R(0))
    > End While
    >
     
    Maarten, Mar 28, 2006
    #2
    1. Advertising

  3. Martin Eyles

    Martin Eyles Guest

    "Maarten" <> wrote in message
    news:...
    > R(0).ToString("yyyy-mm-dd")


    This gives a compiler error - path\filename.ascx.vb(line): 'Public
    Overridable Function ToString() As String' has no parameters and its return
    type cannot be indexed.

    Any more ideas?

    Thanks,
    Martin


    > "Martin Eyles" <> wrote in message
    > news:...
    >> Hi,
    >> I am trying to extract a date from a database, and display it in
    >> yyyy-mm-dd hh:mm:ss format on an ASP.NET webpage. I have been using the
    >> CStr function to turn this into text, but this doesn't give me enough
    >> control to get the right date format. Can anyone suggest a solution?
    >>
    >> Thanks,
    >> Martin
    >>
    >>
    >> 'Snippet of Code I Tried
    >> SQL = ("SELECT " & aDateTime)
    >> anSQLCommand = New System.Data.SqlClient.SqlCommand
    >> anSQLCommand.Connection() = conn
    >> anSQLCommand.CommandText = SQL
    >> R = anSQLCommand.ExecuteReader
    >> While R.Read
    >> displayADateTime = CStr(R(0))
    >> End While
     
    Martin Eyles, Mar 29, 2006
    #3
  4. Martin Eyles

    Pipo Guest

    Sure...

    Dim strDate as string = R(0).ToString()
    strDate = strDate.ToString("mm-yyyy-dd")


    "Martin Eyles" <> wrote in message
    news:...
    > "Maarten" <> wrote in message
    > news:...
    >> R(0).ToString("yyyy-mm-dd")

    >
    > This gives a compiler error - path\filename.ascx.vb(line): 'Public
    > Overridable Function ToString() As String' has no parameters and its
    > return type cannot be indexed.
    >
    > Any more ideas?
    >
    > Thanks,
    > Martin
    >
    >
    >> "Martin Eyles" <> wrote in message
    >> news:...
    >>> Hi,
    >>> I am trying to extract a date from a database, and display it in
    >>> yyyy-mm-dd hh:mm:ss format on an ASP.NET webpage. I have been using the
    >>> CStr function to turn this into text, but this doesn't give me enough
    >>> control to get the right date format. Can anyone suggest a solution?
    >>>
    >>> Thanks,
    >>> Martin
    >>>
    >>>
    >>> 'Snippet of Code I Tried
    >>> SQL = ("SELECT " & aDateTime)
    >>> anSQLCommand = New System.Data.SqlClient.SqlCommand
    >>> anSQLCommand.Connection() = conn
    >>> anSQLCommand.CommandText = SQL
    >>> R = anSQLCommand.ExecuteReader
    >>> While R.Read
    >>> displayADateTime = CStr(R(0))
    >>> End While

    >
    >
     
    Pipo, Mar 29, 2006
    #4
  5. Martin Eyles

    Pipo Guest

    But that's also not the good one ;->

    Here is 1:
    DateTime dte;
    if (DateTime.TryParse(R[0].ToString(), out dte))
    {
    string strDate = dte.ToString("MM-yyyy-dd");
    }


    "Pipo" <> wrote in message
    news:...
    > Sure...
    >
    > Dim strDate as string = R(0).ToString()
    > strDate = strDate.ToString("mm-yyyy-dd")
    >
    >
    > "Martin Eyles" <> wrote in message
    > news:...
    >> "Maarten" <> wrote in message
    >> news:...
    >>> R(0).ToString("yyyy-mm-dd")

    >>
    >> This gives a compiler error - path\filename.ascx.vb(line): 'Public
    >> Overridable Function ToString() As String' has no parameters and its
    >> return type cannot be indexed.
    >>
    >> Any more ideas?
    >>
    >> Thanks,
    >> Martin
    >>
    >>
    >>> "Martin Eyles" <> wrote in message
    >>> news:...
    >>>> Hi,
    >>>> I am trying to extract a date from a database, and display it in
    >>>> yyyy-mm-dd hh:mm:ss format on an ASP.NET webpage. I have been using the
    >>>> CStr function to turn this into text, but this doesn't give me enough
    >>>> control to get the right date format. Can anyone suggest a solution?
    >>>>
    >>>> Thanks,
    >>>> Martin
    >>>>
    >>>>
    >>>> 'Snippet of Code I Tried
    >>>> SQL = ("SELECT " & aDateTime)
    >>>> anSQLCommand = New System.Data.SqlClient.SqlCommand
    >>>> anSQLCommand.Connection() = conn
    >>>> anSQLCommand.CommandText = SQL
    >>>> R = anSQLCommand.ExecuteReader
    >>>> While R.Read
    >>>> displayADateTime = CStr(R(0))
    >>>> End While

    >>
    >>

    >
    >
     
    Pipo, Mar 29, 2006
    #5
  6. Martin Eyles

    Martin Eyles Guest

    "Martin Eyles" <> wrote in message
    news:...
    > "Maarten" <> wrote in message
    > news:...
    >> R(0).ToString("yyyy-mm-dd")

    >
    > This gives a compiler error - path\filename.ascx.vb(line): 'Public
    > Overridable Function ToString() As String' has no parameters and its
    > return type cannot be indexed.
    >
    > Any more ideas?
    >

    It's OK, have fixed the above suggestion, by converting to date before
    converting to string - I think it is awkward because the value comes from
    the database. The code I use is:-
    CDate(R(0)).ToString("yyyy-MM-dd HH:mm:ss")


    Thanks again to everyone for their help,

    Martin

    > Thanks,
    > Martin
    >
    >
    >> "Martin Eyles" <> wrote in message
    >> news:...
    >>> Hi,
    >>> I am trying to extract a date from a database, and display it in
    >>> yyyy-mm-dd hh:mm:ss format on an ASP.NET webpage. I have been using the
    >>> CStr function to turn this into text, but this doesn't give me enough
    >>> control to get the right date format. Can anyone suggest a solution?
    >>>
    >>> Thanks,
    >>> Martin
    >>>
    >>>
    >>> 'Snippet of Code I Tried
    >>> SQL = ("SELECT " & aDateTime)
    >>> anSQLCommand = New System.Data.SqlClient.SqlCommand
    >>> anSQLCommand.Connection() = conn
    >>> anSQLCommand.CommandText = SQL
    >>> R = anSQLCommand.ExecuteReader
    >>> While R.Read
    >>> displayADateTime = CStr(R(0))
    >>> End While

    >
    >
     
    Martin Eyles, Mar 29, 2006
    #6
    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. Andrew J Gray

    asp.net date/time formats

    Andrew J Gray, Mar 4, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    469
    Andrew J Gray
    Mar 4, 2004
  2. David Jessee

    date to text formats - neverending story

    David Jessee, Apr 29, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    361
    Leo Muller
    Apr 29, 2004
  3. Nick

    Date Formats

    Nick, Feb 11, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,911
    Matt Berther
    Feb 17, 2005
  4. Replies:
    0
    Views:
    378
  5. Aparna
    Replies:
    2
    Views:
    549
    Martin Gregorie
    Jun 14, 2007
Loading...

Share This Page