Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Date Formats of Date in Database

Reply
Thread Tools

Date Formats of Date in Database

 
 
Martin Eyles
Guest
Posts: n/a
 
      03-28-2006
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


 
Reply With Quote
 
 
 
 
Maarten
Guest
Posts: n/a
 
      03-28-2006
R(0).ToString("yyyy-mm-dd")

"Martin Eyles" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
Martin Eyles
Guest
Posts: n/a
 
      03-29-2006
"Maarten" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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



 
Reply With Quote
 
Pipo
Guest
Posts: n/a
 
      03-29-2006
Sure...

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


"Martin Eyles" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Maarten" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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

>
>



 
Reply With Quote
 
Pipo
Guest
Posts: n/a
 
      03-29-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Sure...
>
> Dim strDate as string = R(0).ToString()
> strDate = strDate.ToString("mm-yyyy-dd")
>
>
> "Martin Eyles" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> "Maarten" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> 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

>>
>>

>
>



 
Reply With Quote
 
Martin Eyles
Guest
Posts: n/a
 
      03-29-2006

"Martin Eyles" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Maarten" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
Is MKV formats better than other video formats? helena68 Software 3 11-26-2008 07:57 AM
Detailed Analysis of the file formats for M$ Office 2007 -"Microsoft Office XML Formats? Defective by design" Jonathan Walker NZ Computing 1 08-26-2007 03:43 AM
CyberLink Supports UDF 2.5/2.6 Formats For Blu-ray and HD DVD next generation of disc formats. Allan DVD Video 0 07-15-2005 07:43 PM



Advertisments