EasyCFM.COM ColdFusion Forums / ASP to CFML / About Post Date in discussion forum

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: About Post Date in discussion forum

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

Sandy
04-05-2005 @ 11:22 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 16
Joined: Apr 2005

I'm developing a discussion forum using coldfusion, referencing a ASP book, could you pls tell me how can I write the following ASP code using coldfusion? It is the code for showing the post date in discussion forum?  Many thanks!

<input type="hidden" name="d" value="<%response.Write(date())%>">

maquiladoras
04-05-2005 @ 11:36 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2073
Joined: Dec 2002

Erm,
I have to question the point of putting the date in a form field? that makes no sense, you can just create the date upon updating the SQL

heres what i'd do

1. Make sure the column you are inserting to is a DATETIME type

2. In your SQL, make sure your SQL looks something like this

<CFQUERY NAME="insertReply" DATASOURCE="myDSN">
INSERT INTO replies (reply_message, reply_date)
VALUES (
    '#form.message#',
    <cfqueryparam value="#createODBCDateTime(now())#" cfsqltype="CF_SQL_TIMESTAMP">
       )
</CFQUERY>

3. When you want to output the date you can do it like this

Date: #DateFormat(reply_date, "mm/dd/yyyy")#
Time: #TimeFormat(reply_date, "hh:mmtt")#

hopefully that helps


-
"There is no justice, There is Just Us"
-

This message was edited by maquiladoras on 4-5-05 @ 11:36 PM

Sandy
04-06-2005 @ 1:14 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 16
Joined: Apr 2005

Thanks!  I've tried to incorporate the code you suggest in my page(in PostDate)as follows but it can't work, could u pls advise me again?  Many thanks!

<cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
<cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "form1">
  <cfquery datasource="03vmatch">
  INSERT INTO tbMessage (UserName, Gender, Topic, Message, PostDate) VALUES (
     <cfif IsDefined("FORM.UserName") AND #FORM.UserName# NEQ "">
    '#FORM.UserName#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.Gender") AND #FORM.Gender# NEQ "">
    '#FORM.Gender#'
      <cfelse>
      NULL
  </cfif>
  ,
  <cfif IsDefined("FORM.Topic") AND #FORM.Topic# NEQ "">
    '#FORM.Topic#'
      <cfelse>
      NULL
  </cfif>
  ,
<cfif IsDefined("FORM.Message") AND #FORM.Message# NEQ "">
    '#FORM.Message#'
      <cfelse>
      NULL
  </cfif>
   ,
<cfif IsDefined("FORM.PostDate") AND #FORM.PostDate# NEQ "">
   #FORM.PostDate#,
<cfqueryparam value="#createODBCDateTime(now())#" cfsqltype="CF_SQL_TIMESTAMP">
      <cfelse>
      NULL
  </cfif>
   )
  </cfquery>
  <cflocation url="discussion_forum.cfm">
</cfif>

Anything to do with input? such as:
  <input type="hidden" name="PostDate" value="<cfoutput>#DateFormat(Now(),"mm/dd/yyyy")#</cfoutput>"> ?  
I've tried to make this referening the ASP code like <input type="hidden" name="d" value="<%response.Write(date())%>">


maquiladoras
04-06-2005 @ 7:26 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2073
Joined: Dec 2002

you dont need the form var though
what would be the point?
you just insert the date through SQL.

Also you are better off using CFPARAM for your query
basically CFPARAM will set a default value if something isnt specified, thus eliminated tonnes of CFIFs

But one thing is though, there are some you definitely don't want to be NULL, like the username? do you really want it to be null?

but looking at your table there, theres nothing you want to be null, except maybe the gender

anyway in short

look up CFPARAMS, get rid of the CFIF's, delete the form.postdate

-
"There is no justice, There is Just Us"
-

Sandy
04-06-2005 @ 12:41 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 16
Joined: Apr 2005

Thanks for your suggestion.  But I am not so familiar with coldfusion, not quite understand the logic behind, so I don't know how to change the code according to your suggestion.  Could u pls do me one more favour of changing the codes for me?  Million thanks!


Website Designed and Developed by Pablo Varando.