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!

Displaying a date from a SQL server 3

Status
Not open for further replies.

rojas1mg

Programmer
Jun 15, 2004
119
US
Hello everyone. I have a datetime field in SQL and it stores date & time and I'd like to display "just" the date on the .cfm. How do I convert the data retreived in the query? Thanks.
 
Use the DateFormat() function in your output.
Code:
<cfouput query="QueryName">
#DateFormat(FieldName, 'mm/dd/yy')#
</cfoutput>



Hope This Helps!

Ecobb

&quot;My work is a game, a very serious game.&quot; - M.C. Escher
 
Or you could return the date, already formatted, from SQL Server:

SELECT CONVERT(varchar(10),dateField,101) AS dateField

This will return every column named dateField that is a datetime or smalldatetime in the format "mm/dd/yyyy". Look up the CONVERT function in SQL Server Books Online to see alternate formats.

-Tek
 
Ecobb is right, and that's the solution I would have posted, but I'd take Tek's suggestion into consideration... If your output is a heavily visited page or outputs many dates..

It is better to share the load..

A lot of developers, for instance, run insert queries like this..

INSERT INTO TABLE(cID,Date)
VALUES('#form.cID#','#Now()#')

And while that's nice, with most databases, you can set the default of the field in the db to the current time (at insert) so that your query only needs to be.

INSERT INTO TABLE(cID)
VALUES('#form.cID#')

Just my thoughts...

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top