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

How do I convert this javascript code into a UserDefinedFunction?

Status
Not open for further replies.

jruiseco

Programmer
Oct 10, 2001
52
0
0
US
The javascript below grabs the user's date (client date) from their computer and returns the value.

I want to turn this javascript (and a time javascript) into a user defined function. I spent a lot of time on this and couldn't figure it out.

<!--- Start Script --->

<script>
function briefclientdate(){
var currentdate = new Date()
var numday = currentdate.getDate()
var nummonth = currentdate.getMonth()
var numyear = currentdate.getYear()
var monthname = &quot;01&quot;
// Start changing the month number to an actual labeled month name.
if (nummonth == 1) {
var monthname = &quot;02&quot;
}
if (nummonth == 2) {
var monthname = &quot;03&quot;
}
if (nummonth == 3) {
var monthname = &quot;04&quot;
}
if (nummonth == 4) {
var monthname = &quot;05&quot;
}
if (nummonth == 5) {
var monthname = &quot;06&quot;
}
if (nummonth == 6) {
var monthname = &quot;07&quot;
}
if (nummonth == 7) {
var monthname = &quot;08&quot;
}
if (nummonth == 8) {
var monthname = &quot;09&quot;
}
if (nummonth == 9) {
var monthname = &quot;10&quot;
}
if (nummonth == 10) {
var monthname = &quot;11&quot;
}
if (nummonth == 11) {
var monthname = &quot;12&quot;
}
else {
// Do nothing...
}
document.write(&quot;&quot; +monthname+ &quot;/&quot; +numday+ &quot;/&quot; +numyear)
}
briefclientdate()
</script>
 
It's not clear what you mean by a 'user defined function'. And what does this have to do with ColdFusion?

Are you meaning you want to turn this JavaScript code into Coldfusion?

Please be more specific so we can help you appropriately.

 
I am trying to accomplish the same thing using CFSCRIPT instead of javascript.

User defined functions are a new feature in ColdFusion Server 5.0 that allow you to write your own functions for use in an application or on a server basis.

Cheers...

 
I also am not sure what you are trying to do, but why not use already existing ColdFusion functions to manipulate the date. If you need to reuse code, try creating an include template and use <cfinclude template=&quot;pathname/includefilename.cfm&quot;>
Here are some examples of manipulating date and time adapted from ColdFusion help.

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
<head>
<title>Test</title>
</head>

<body>
<cfoutput>#now()#</cfoutput><br>
<CFOUTPUT>#DateFormat(Now())#, #TimeFormat(Now())#</CFOUTPUT>
<cfset yourdate = #now()#>
<CFOUTPUT>
<P>Your date, #DateFormat(yourDate)#.
<BR>It is #DayofWeekAsString(DayOfWeek(yourDate))#, day
#DayOfWeek(yourDate)# in the week.
<BR>This is day #Day(YourDate)# in the month of
#MonthAsString(Month(yourDate))#, which has
#DaysInMonth(yourDate)# days.
<BR>We are in week #Week(yourDate)# of #Year(YourDate)# (day
#DayofYear(yourDate)# of #DaysinYear(yourDate)#).
<BR><CFIF IsLeapYear(Year(yourDate))>This is a leap year
<CFELSE>This is not a leap year</CFIF>
</CFOUTPUT>

</body>
</html>
 
Check out the following URL.


All of my sites are hosted in the UK. But I want to report back the users date/time in my applications, not my servers date/time. I can do that using the javascript above. But I want to create a ColdFusion user defined function to do this.
 
ok, here is concept you might want to use:

step 1.
start with a &quot;dummy&quot; page (index.html or something) that will use JavaScript and form with hidden form fields to collect date and time info from the client; use onload or unload event to submit that form with it's value to ColdFusion server for processing and froward it to the main template;

step2.
write template that will accept the submitted values and process them; in that template you can simply use CreateDate() or CreateDateTime() function to create valid local date; now with that done, you can set session variable to make the new local date available to the particular client;



Sylvano
dsylvano@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top