SunQuest
           .Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old April 29th, 2008, 07:29 PM
adam_leerox adam_leerox is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 143 adam_leerox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 12 h 46 m 29 sec
Reputation Power: 2
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
__________________
Web Design | Website Hosting | Email Marketing

Reply With Quote
  #2  
Old April 30th, 2008, 03:14 AM
atlantisstorm atlantisstorm is offline
Hang your freedom higher.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 622 atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 7 h 28 m 48 sec
Reputation Power: 135
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!!"

Reply With Quote
  #3  
Old April 30th, 2008, 05:15 PM
adam_leerox adam_leerox is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 143 adam_leerox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 12 h 46 m 29 sec
Reputation Power: 2
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">

Reply With Quote
  #4  
Old May 1st, 2008, 09:12 AM
danielk's Avatar
danielk danielk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: Earth
Posts: 207 danielk User rank is Lance Corporal (50 - 100 Reputation Level)danielk User rank is Lance Corporal (50 - 100 Reputation Level)danielk User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Days 23 h 20 m 15 sec
Reputation Power: 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

Reply With Quote
  #5  
Old May 1st, 2008, 05:30 PM
adam_leerox adam_leerox is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 143 adam_leerox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 12 h 46 m 29 sec
Reputation Power: 2
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 = " %>'

Reply With Quote
  #6  
Old May 2nd, 2008, 07:00 AM
danielk's Avatar
danielk danielk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: Earth
Posts: 207 danielk User rank is Lance Corporal (50 - 100 Reputation Level)danielk User rank is Lance Corporal (50 - 100 Reputation Level)danielk User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Days 23 h 20 m 15 sec
Reputation Power: 4
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Date Display MySQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway