Welcome!

Charlie Arehart

Subscribe to Charlie Arehart: eMailAlertsEmail Alerts
Get Charlie Arehart via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Article

Easier Insertion of Dates with CFINSERT/CFUPDATE

Easier Insertion of Dates with CFINSERT/CFUPDATE

When you're inserting date/time values into a database, you want to be careful about deciding whether the date should be hardcoded into the form (perhaps as a hidden field) or whether it should be computed at the time of the data entry. These could each present very different date/time values.

One challenge when using CFINSERT is that you typically rely on the form to present all data for insert into the database, so you may feel restricted to hard-coding the date/time into the form.

In 4.01, this problem has been addressed. When using CFINSERT or CFUPDATE, you can define a form field with the name of a table column that will hold a date or time, and you can now store a special "value" for that field on the form: "currentdate()", or "currentdatetime()". Note that you do NOT wrap this in pound signs in the form. It's a special string value interpreted during the CFINSERT/CFUPDATE on the action page. And more important, the value is computed to be that at the time of the insert or update, which is usually what one intends.

This is documented only in the 4.0.1 documentation update page (not in the CFML reference for the tags). Also, the doc does not mention the currentdatetime() existing, but testing showed it to work as expected.

More Stories By Charlie Arehart

A veteran ColdFusion developer since 1997, Charlie Arehart is a long-time contributor to the community and a recognized Adobe Community Expert. He's a certified Advanced CF Developer and Instructor for CF 4/5/6/7 and served as tech editor of CFDJ until 2003. Now an independent contractor (carehart.org) living in Alpharetta, GA, Charlie provides high-level troubleshooting/tuning assistance and training/mentoring for CF teams. He helps run the Online ColdFusion Meetup (coldfusionmeetup.com, an online CF user group), is a contributor to the CF8 WACK books by Ben Forta, and is frequently invited to speak at developer conferences and user groups worldwide.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Ann Bernstein 04/21/04 03:58:29 PM EDT

This doesn''t work in our installation of ColdFusion MX 6.1. We had to replace all instances of currentdate() with #now()# and it worked fine.