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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date time validation

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Hi,
I have 3 fields for displaying date and time and am/pm in the form.
I need to validate these 3 fields in the form and in the action i need to concatenate them into one.
But I am having problem when concatenating "am/pm" field. It concatenates "am" irrespective of whatever i select in the form for that field. Please let me know how to do it.
Here is my code:
Form
-----
<cfinput type=&quot;Text&quot; name=&quot;request_date&quot; value=&quot;#DateFormat(url.r_date,'mm/dd/yy')#&quot; message=&quot;Please enter date using mm/dd/yy format.&quot; validate=&quot;date&quot; required=&quot;Yes&quot; size=&quot;6&quot;>


<input type=&quot;hidden&quot; name=&quot;r_Date_date&quot; VALUE=&quot;Please enter date using mm/dd/yy format.&quot;>

<cfinput type=&quot;Text&quot; name=&quot;r_time1&quot; value=&quot;#TimeFormat(url.request_date,'HH:mm:ss')#&quot; size=&quot;6&quot; message=&quot;Please enter time using hh:mm:ss format.&quot; validate=&quot;time&quot; required=&quot;Yes&quot; >

<select name=&quot;r_time2&quot;>
<option value=&quot;AM&quot; <cfif #TimeFormat(url.request_date,'tt')# eq 'AM'>selected</cfif>>AM
<option value=&quot;PM&quot; <cfif #TimeFormat(url.request_date,'tt')# eq 'PM'>selected</cfif>>PM
</select>

<input type=&quot;hidden&quot; name=&quot;r_time1_time&quot; VALUE=&quot;Please enter Request Time using 'hh:mm:ss' format.&quot;>

<input type=&quot;submit&quot; name=&quot;save&quot; value=&quot;Save&quot;>

action:
------
<cfoutput>
<Cfset r_date=#dateformat(form.r_date,'mm/dd/yy')#>
<cfset r_time=#TimeFormat(form.r_time1,'hh:mm:ss')# & #form.r_time2#>
<cfset r_time=#timeformat(form.r_time1,'hh:mm:ss tt')#>
<cfset final_date='#r_date# #r_time#'>
#final_date#
#createodbcdatetime(r_date)#
</cfoutput>

Thanks in advance
 
Try this -- this should work:

<cfset Year = DatePart(&quot;yyyy&quot;,form.r_date)>
<cfset Month = DatePart(&quot;m&quot;,form.r_date)>
<cfset day = DatePart(&quot;d&quot;,form.r_date)>

<cfif form.r_time2 is &quot;PM&quot;>
<cfset hour = Hour(form.r_time1) + 12> <!--- Add 12 for military time --->
<cfelse>
<cfset hour = Hour(form.r_time1)>
</cfif>
<cfset Minute = Minute(form.r_time1)>
<cfset Second = Second(form.r_time1)>

<cfoutput>

<cfset final_date = CreateDateTime(year,Month,Day,hour,minute,second)>
#final_date#
#createodbcdatetime(final_date)#

#Hour# #Minute# #Second#
</cfoutput>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top