|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Date Display MySQL
I'm trying to fix up some .net code someone did without the knowledge of .net (php developer).
I have a form which updates mysql. One field is a date field, the update works but when I call it the format is wrong. I have this code: <%# dsFeatureEdit.FieldValue("FStartDate", Container) %> which displays the date as: 4/30/2008 12:00:00 AM While the date from Mysql is YYYY-MM-DD (2000-30-04) and this is how I want it to display when called. Is there an easy way to do this? Thanks |
|
#2
|
|||
|
|||
|
You just need to change the format of the date field return in your sql statement...
Code:
date_format(FStartDate,'%y-%m-%d') as 'FStartDate' ...(presuming the date field in question is called FStartDate)
__________________
"Badges? We ain't got no badges. We don't need to badges! I don't have to show you any stinkin' badges!!" |
|
#3
|
|||
|
|||
|
Thanks for your reply.
So I changed from this: SELECT * FROM features WHERE FID = ? to SELECT FName, FImage, date_format(FStartDate,'%y-%m-%d') as FStartDate, FEndDate, FOnline FROM features WHERE FID = ? but then I am getting an error: Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: The server tag is not well formed. (Line 48 - In Red Below) Code:
<MM:DataSet
id="dsFeatureEdit"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_aConn") %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_aConn") %>'
CommandText='<%# "SELECT FName, FImage, date_format(FStartDate,'%y-%m-%d') as 'FStartDate', FEndDate, FOnline FROM features WHERE FID = " %>'
Debug="true">
|
|
#4
|
||||
|
||||
|
you have nested quotes ' within quoutes '
ie '<%# "SELECT FName, FImage, date_format(FStartDate,'%y-%m-%d') as 'FStartDate', FEndDate, FOnline FROM features WHERE FID = " %>' try setting this property in the code behind or escaping the quotes |
|
#5
|
|||
|
|||
|
OK, how would I escape the quotes? I tried things such as \' or '' or '" etc but nothing worked...
Thanks '<%# "SELECT FName, FImage, date_format(FStartDate,'%y-%m-%d') as 'FStartDate', FEndDate, FOnline FROM features WHERE FID = " %>' |
|
#6
|
||||
|
||||
|
you could just set this in your code behind. ie
dsFeatureEdit.CommandText = "SELECT FName, FImage, date_format(FStartDate,'%y-%m-%d') as 'FStartDate', FEndDate, FOnline FROM features WHERE FID = " and remove it from your .aspx file. It is good practice to keep your data access code out of your user interface code anyway. Ideally this code would go in a data access layer or stored procedure. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > .Net Development > Date Display MySQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|