PC Review


Reply
Thread Tools Rate Thread

Date Formats of Date in Database

 
 
Martin Eyles
Guest
Posts: n/a
 
      28th Mar 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
 
      28th Mar 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
 
      29th Mar 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
 
      29th Mar 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
 
      29th Mar 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
 
      29th Mar 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
Rate This Thread
Rate This Thread:

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
Different Date formats in text to be recognised as date value swiftcode Microsoft Excel Programming 8 16th Oct 2009 08:37 AM
Cell Date and Listbox Date formats Corey Microsoft Excel Programming 5 12th Dec 2008 11:52 AM
Dealing with date formats on expiration date bliten_bsas Microsoft Excel Programming 1 4th Oct 2007 08:47 PM
All date formats change any date input to Sept. 17, 2126. =?Utf-8?B?SmVycnk=?= Microsoft Excel Crashes 0 28th Aug 2006 07:34 PM
Database Queries/Date Formats daver676 Microsoft Excel Misc 2 26th Aug 2003 10:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:18 PM.