473,379 Members | 1,260 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Date Formats of Date in Database

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
Mar 28 '06 #1
5 1700
R(0).ToString("yyyy-mm-dd")

"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message
news:12*************@corp.supernews.com...
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

Mar 28 '06 #2
"Maarten" <No****@me.com> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
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" <ma**********@NOSPAMbytronic.com> wrote in message
news:12*************@corp.supernews.com...
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

Mar 29 '06 #3
Sure...

Dim strDate as string = R(0).ToString()
strDate = strDate.ToString("mm-yyyy-dd")
"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message
news:12*************@corp.supernews.com...
"Maarten" <No****@me.com> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
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" <ma**********@NOSPAMbytronic.com> wrote in message
news:12*************@corp.supernews.com...
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


Mar 29 '06 #4
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" <Pa****@Mayo.com> wrote in message
news:uh**************@tk2msftngp13.phx.gbl...
Sure...

Dim strDate as string = R(0).ToString()
strDate = strDate.ToString("mm-yyyy-dd")
"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message
news:12*************@corp.supernews.com...
"Maarten" <No****@me.com> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
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" <ma**********@NOSPAMbytronic.com> wrote in message
news:12*************@corp.supernews.com...
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



Mar 29 '06 #5

"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message
news:12*************@corp.supernews.com...
"Maarten" <No****@me.com> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
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" <ma**********@NOSPAMbytronic.com> wrote in message
news:12*************@corp.supernews.com...
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


Mar 29 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
15
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
3
by: Mike Dundee | last post by:
I am importing data into a new database (the database still has to be set up) and have a problem. The comma delimited text files I am importing have four fields containing date and date/times. ...
9
by: Bob Achgill | last post by:
I would like to use the timestamp on files to manage the currency of support files for my VB windows application. In this case I would only put the timestamp of the file in the management database...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
2
by: x | last post by:
hi i am a pilot by profession. i want to create a database of my logbook using ms access 2002. i am facing a problem regarding the format of time field. when i select "Data/Time" data type for my...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
10
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a...
30
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.