Skip to main content
Inspiring
March 6, 2008
Answered

add 4 hours to a variable

  • March 6, 2008
  • 1 reply
  • 402 views
I need to add 4 hours to a variable. This is the variable:
<cfparam name="application.startFacTime" default = "#Dateformat(now())#" />

I want to compare application.startFacTime + 4 hours to Now.

If Now and the variable are the same date, I want to see if adding 4 hours to the
variable will result a time that's 4 or more hours older than Now.

If that's true, I run a query and do some other stuff and then
reset the variable to Dateformat(now())

Thanks for any help!
This topic has been closed for replies.
Correct answer JoyRose
This works:

<cfparam name="application.startFacTime" default = "#dateAdd('h',4, now())#" />

Thanks for your earlier reply.

1 reply

Inspiring
March 6, 2008
Step number 1 - delete the dateformat function in your cfparam tag. It returns a string and you want a datetime object.

Step number 2 - create a new variable with by adding 4 hours to the application variable.

Step 3 - see if the day portions of your application variable and new variables are the same.

If you don't know how to do steps 2 and 3, google "coldfusion date functions".
JoyRoseAuthor
Inspiring
March 6, 2008
Can you show me what the code would look like: "create a new variable with by adding 4 hours to the application variable"


I can't seem to get any code to work that adds 4 hours to the variable.

For instance:
1.)<CFIF....
IsDefined("application.startFacTime") AND (
DateCompare(DateFormat(application.startFacTime),DateFormat(now())) is 0 AND
DateCompare(Hour(application.startFacTimeMin),Hour(now())) is -1>

This works to compare the variable to Now, but that doesn't do any good.

I need something like this pseudo-code:

DateCompare(Hour(application.startFacTimeMin)+4 hours,Hour(now())) is -1



2.) This "works" but, like above, it doesn't do me any good:
<CFIF....
DateCompare(application.startFacTime,DateFormat(now())) is 0 AND
#Abs(DateDiff('h', application.startFacTime, Dateformat(now())))# lt 1
</cfif>

I need something like this pseudo-code:
#Abs(DateDiff('h', application.startFacTime + 4 hours, Dateformat(now())))# lt 1

Thanks for your help.
JoyRoseAuthorCorrect answer
Inspiring
March 6, 2008
This works:

<cfparam name="application.startFacTime" default = "#dateAdd('h',4, now())#" />

Thanks for your earlier reply.