Categories
Mastering Development

need help formating type=”datetime-local” in ColdFusion (not a cold fusion element)

Ok I have searched for 2 days and thought I found the solution but it’s not working maybe I can get a hand here.

I’m trying to allow the user to choose the date and time of their form post. I found the type="datetime-local" which achieves this (even though it’s not widely supported by browsers it still seems to work for my purposes.)

form element:

<input name="PostDate" type="datetime-local" (the version of CF which we are using has the cfcalendar deprecated)

My cfform method is "post" and my action is "submit.cfm"

When we get to the submit.cfm page I’m using the following CF code to format the date to go into MSSQL database:

<cfset PostDate=Replace(PostDate,"T"," ","All")><br>
<cfset PostDate = DateTimeFormat (PostDate, "yyyy-MM-dd HH:nn:ss")>

and the output says that the date is formatted correctly:

But… when I try to cfinsert the date into the database it seems like the formatted date was not saved in the #PostDate# variable (this error is being thrown by the MSSQL database server:

And for completeness of information this is how the table in the database is set up:


this is the code for the submit.cfm


<cfmodule template="customTags/front.cfm" >
<cfoutput>
    <p>Date before format: #PostDate#</p>
</cfoutput>
<cfset PostDate=Replace(PostDate,"T"," ","All")>
<cfset PostDate = DateTimeFormat (PostDate, "yyyy-MM-dd HH:nn:ss")>
<br>
<cfoutput>
    <p>Title: #PostTitle#</p> 
    <p>Date after format: #PostDate#</p>
    <p>Author ID: #UserID#</p>
    <p>Category ID: #CategoryID#</p>
    <p>Post Text: #Post#</p>
</cfoutput>
<hr>
<!--- Insert the new record --->
<cfinsert datasource="Intranet" tablename="TBL_POST">
<h1>Post Added</h1>
<cfoutput> You have added #Form.PostTitle#.</cfoutput>  
</cfmodule>

As a last qualification for this ask I need to say I’m an absolute beginner at ColdFusion (our state agency uses it) and it’s been over ten years since I’ve written an HTML form.

I appreciate all the help I can get.

Leave a Reply

Your email address will not be published. Required fields are marked *