Solved

CF Oracle date woes

Posted on 2004-09-05
10
236 Views
Last Modified: 2013-12-24
I am creating an event calendar where users will be able to enter in an event title, comments and then that events start and end date/time.

I need help creating a form that accepts the following submission information:
title                     VARCHAR
comments           VARCHAR
dt_start               DATE
dt_end                DATE


When the form submits I'd like it to check if there is already an event within dt_start and dt_end. If so, do not submit it and give the user an error.   If not, then insert into the database.

How do I do this?   I'm completely lost and would appreciate a simple walkthrough.  Anyone?
0
Comment
Question by:kkhipple
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 21

Assisted Solution

by:pinaldave
pinaldave earned 50 total points
ID: 11984595


<form action="action page" post="post">
<input type="text" name="" value="">
<input type="text" name="" value="">
<input type="text" name="" value="">
<input type="text" name="" value="">
<input type="submit" type="submit" value="submit">
</form>

now on your action page
<cfquery name="select_q" datasource="dsn">
select * from your table where dt_start <= #form.dt_start# and dt_end >= #form.dt_end#
</cfquery>

<cfif select_q.recordcount > 0 >
you can not insert your query
</cfelse>
<cfquery name-"insert_q" datasrouce="dsn">
your insert query
</cfquery>
0
 
LVL 11

Accepted Solution

by:
hart earned 200 total points
ID: 11988209
some corrections pinal

he wants to check events in between the two dates...

and why use select * in a query where u r checking count...

Select * should be avoided if possible...

<cfquery name="Qry_CheckEvent" datasource="dsn">
    select count(title) from your table
    where dt_start >= <CFQUERYPARAM CFSQLTYPE="CF_SQL_DATE" VALUE="#form.dt_start#"> and dt_end <= <CFQUERYPARAM CFSQLTYPE="CF_SQL_DATE" VALUE="#form.dt_end#">
</cfquery>

now this will check if theres any event that is scheduled between the start and end date..
but if u r checking for events that just start between these dates then change the query a little...

<cfquery name="Qry_CheckEvent" datasource="dsn">
    select count(title) from your table
    where dt_start >= <CFQUERYPARAM CFSQLTYPE="CF_SQL_DATE" VALUE="#form.dt_start#"> and dt_start <= <CFQUERYPARAM CFSQLTYPE="CF_SQL_DATE" VALUE="#form.dt_end#">
</cfquery>



Regards
Hart
0
 
LVL 5

Author Comment

by:kkhipple
ID: 11990070
how do i also verify that they are entering the right date/time format?
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 11

Expert Comment

by:hart
ID: 11994977
u can do it when the form is submitted...

you can use javascript to check if the data entered is proper or not...

One of the way is give the calender pop ups...
Other way would be to do a server side check and see if the data that has been sent in is as per the format....

Also you could give drop downs for dd mm and yyyy in the form which will make the user only select an appropriate date

Regards
Hart
0
 
LVL 5

Author Comment

by:kkhipple
ID: 11996227
how do i have coldfusion conform the date entry into whats allowed on oracle db
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11998085
thanks Hart for correcting me.
Regards,
---Pinal
0
 
LVL 5

Author Comment

by:kkhipple
ID: 12000821
here's where im having my problem....

here is the code when the submit happens:

<CFQUERY DATASOURCE="lieu" NAME="getMaxId">
      SELECT max(id) as max_id FROM lieu_events
</CFQUERY>

<CFSET event_id = getMaxId.max_id + 1>
<CFSET dt_start = 'DATEFORMAT(zDate, "mm/dd/yyyy") TIMEFORMAT(zTime, "hh:mm:ss")'>
<CFSET dt_end = 'DATEFORMAT(zDate, "mm/dd/yyyy") TIMEFORMAT(zTime, "hh:mm:ss")'>

<CFOUTPUT>#event_id#</CFOUTPUT>
<CFOUTPUT>#dt_start#</CFOUTPUT>
<CFOUTPUT>#dt_end#</CFOUTPUT>

<CFQUERY DATASOURCE="lieu" NAME="addEvent">
      INSERT INTO lieu_events
      VALUES ('#event_id#','#SESSION.lieu_user_name#',
            <CFQUERYPARAM VALUE = "dt_start" CFSQLType = "CF_SQL_DATE">,
            <CFQUERYPARAM VALUE = "dt_end" CFSQLType = "CF_SQL_DATE">,
            '#FORM.title#', '#FORM.comment#', 'PENDING')
</CFQUERY>



However, this produces the following error:

Error Occurred While Processing Request
Error Diagnostic Information
CFQUERYPARAM data conversion error


There is a data conversion error for CFQUERYPARAM #1.

SQL = "INSERT INTO lieu_events VALUES ('8','khippl-k', _CF_:?_, _CF_:?_, '12312', 'asdfasdf', 'PENDING')"

Query Parameter Value(s) -

Parameter #1 = dt_start

Parameter #2 = dt_end
 

Anyone can point out what's wrong with code?
0
 
LVL 5

Author Comment

by:kkhipple
ID: 12000925
figured it out... for those that similiar problems....

<CFPARAM name="dtstamp" default="#dateformat(zDate,'dd-mmm-yy')# #timeformat(zTime,'HH:mm:ss')#">

<CFOUTPUT>#event_id#</CFOUTPUT>
<CFOUTPUT>#dt_start#</CFOUTPUT>
<CFOUTPUT>#dt_end#</CFOUTPUT>

<CFQUERY DATASOURCE="lieu" NAME="addEvent">
      INSERT INTO lieu_events
      VALUES ('#event_id#','#SESSION.lieu_employee_id#',
            to_date('#dtstamp#','YYYY-MM-DD HH24:MI:SS'),
            to_date('#dtstamp#','YYYY-MM-DD HH24:MI:SS'),
            '#FORM.title#', '#FORM.comment#', 'PENDING')
</CFQUERY>


this atleast does the insert. now im trying to figure out how to add a duration (FORM.duration) to the start time.
0
 
LVL 5

Author Comment

by:kkhipple
ID: 12001265
finally after some date insert and retrieval issues... here's what works for me. thanks pinaldave and hart.  sometimes we all just need a little direction.....  here's another snippet, with similiar issues.


<!---- create the start and end date/time---->
<CFPARAM name="dt_start" default="#dateformat(zDate,'YYYY-DD-MM')# #timeformat(t_start,'HH:mm:ss')#">
<CFPARAM name="dt_end" default="#dateformat(zDate,'YYYY-DD-MM')# #timeformat(t_end,'HH:mm:ss')#">

<!--- insert into db --->
<CFQUERY DATASOURCE="lieu" NAME="addEvent">
      INSERT INTO lieu_events
      VALUES ('#event_id#','#SESSION.lieu_employee_id#',
            to_date('#dt_start#','YYYY-DD-MM HH24:MI:SS'),
            to_date('#dt_end#','YYYY-DD-MM HH24:MI:SS'),
            '#FORM.title#', '#FORM.comment#', 'PENDING')
</CFQUERY>
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12001271
glad that it worked for you.
Good day,
Regards,
---Pinal
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change local server setting in php 6 105
ip / url redirect 13 74
Domino Website - Redirection 12 99
Help with a redirect in web.config file 8 65
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question