views:

142

answers:

2

I'm relatively new to CF / Flex3 and I've been tasked with making mock applications in order to get my knowledge of the 2 languages up.

I'm creating an application where I require data back 1 week (strtotime equiv '-1 week').

So that the result is always 1 weeks worth.

Whats the comparable equivalent if any for coldfusion? If none, how would I accomplish this task? Just curious, I've searched but cannot find anything yet on this topic.

How I solved this (get data from 'last friday'):

<cfset lastweek = dateAdd("d", -(DayOfWeek(now()) + 1), now()) />


strtotime
Parse about any English textual datetime description into a Unix timestamp

+4  A: 

I don't know of a way in coldfusion (not natively anyway) that will take a textual representation of time and do a conversion. A few google searches also did not turn up anything. It could be written but would not be a simple undertaking.

That said, if you want to get a date 1 week back, you could do something like this using the dateadd() function:

<cfset variables.lastweek = dateAdd("w",-1,now()) />

or

<cfset variables.lastweek = dateAdd("d",-7,now()) />

Of course you can substitute now() out for any timestamp or date.

Update:

Remember that because CF is java, you can use any java classes to help you on your way too. It doesn't look like there is a cut and dry equivallent even in java, but these relevant topics may help you on your way:

http://stackoverflow.com/questions/1236678/phps-strtotime-in-java

http://stackoverflow.com/questions/1268174/phps-strtotime-in-java

Ryan Guill
How would I accomplish this if I needed data from 'last friday' for instance? Thats whats making me scratch my head...
Jakub
Jakub, use DayOfWeek to get current day, subtract that to get start of week, then subtract two/three days to get the friday.
Peter Boughton
@jakub, like @peter boughton says, you would need to do the math to figure out what last friday is. And that does seem like a lot of work, but it will more than likely run faster and be much less prone to error. The problem with language translation like this is that it is "fuzzy", there can be multiple meanings for the same thing. It is a nice thing to have when relying on user input, but in your code it is better to do the appropriate math.
Ryan Guill
Thanks gents, that put me on the right path.
Jakub
+1  A: 

Maybe ParseDateTime will do the job?

Sergii
It's the closest function, but it doesn't do natural language conversion of things like 'last friday'.
Peter Boughton