Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFGridcolumn and Date Formatting

Status
Not open for further replies.

Chloeee

Programmer
Jan 16, 2001
27
US
Is there a way to format a date that is displayed via CFGrid in a grid column? I see that there is a number format mask attribute to the CFGridcolumn tag, but what about dates?
 
Nope. The contents of the column. Right now they display as this convoluted mess of numbers. I would like to present the data in the format mm-dd-yy. I can do this in regular cfoutput statements, but within the cfgridcolumn, hmmmm... Any wisdom is appreciated.
 
The following code is from a site administrative interface that displays a grid within a cfform that allows the user to update the scores of games as they are played. In Access, the column GameDate is of datatype "short date". However, in the grid, the GameDate displays in the format 2001-01-23 00:00:00. I need to see this formatted as 01-23-01 instead.

Code:
<cfgrid name=&quot;theupdate&quot; query=&quot;get_data&quot; selectmode=&quot;edit&quot; sort=&quot;Yes&quot; sortascendingbutton=&quot;Ascending&quot; sortdescendingbutton=&quot;Descending&quot; colheaderalign=&quot;center&quot; colheaderbold=&quot;Yes&quot; height=&quot;400&quot; width=&quot;610&quot;>
  <cfgridcolumn name=&quot;GameID&quot; display=&quot;No&quot;>
  <cfgridcolumn name=&quot;GameDate&quot; header=&quot;Game Date&quot;>
  <cfgridcolumn name=&quot;HomeTeam&quot; header=&quot;Home Team&quot;>
  <cfgridcolumn name=&quot;HomeTeamScore&quot; header=&quot;Score&quot;>
  <cfgridcolumn name=&quot;AwayTeam&quot; header=&quot;Away Team&quot;>
  <cfgridcolumn name=&quot;AwayTeamScore&quot; header=&quot;Score&quot;>
  <cfgridcolumn name=&quot;Played&quot; header=&quot;Played?&quot;>
</cfgrid>
 
I am pretty sure you will need SQL to do the trick for you, since only number formatting is enabled in cfgridcolumn.
The following query should work for SQL Server, I am not sure though if it works for Access.

<cfquery name=&quot;get_data&quot; datasource=&quot;vbdweb2&quot;>
SELECT GameId, CONVERT(varchar, GameDate, 10) AS MyGameDate, HomeTeam, HomeTeamScore, AwayTeam, AwayTeamScore, Played
FROM MyTable
</cfquery>

Note that &quot;10&quot; is the constant to convert a date to a standard USA date (as you requested ;-) ), without the century. Also note that you put MyGameDate in the CFGRIDCOLUMN as query column, plus that it is not a date object anymore. Remember this before you try to put the value of this column in a database.

Hope this helps...

<webguru>iqof188</webguru>
 
Arrghh... Nope. Access doesn't recognize the Convert function, but I see the logic here. I'll continue to investigate how Access can do this. Thanks for pointing me in the right direction!
 
Chloeeee, relax man, tell me what version of Access you are using (and I won't ask WHY the ... you use Access :) ). Maybe I or someone else (GunJack or iza?) can help you with a substitute for the CONVERT function. Maybe someone in the Access forums has an answer to your question, check it out.
Bottom line is that your date conversion should take place in your query. Good luck!

<webguru>iqof188</webguru>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top