x
Solved

# Finding out number of weeks by date range

Posted on 2006-07-23
Medium Priority
1,006 Views
I have a record with a date range.  Is there a way to determine the number of weeks that is included in the date range?
0
Question by:moyedokun

LVL 11

Expert Comment

ID: 17165057
Say for example you have a record like 07/23/2006-07/20/2006

You can do something like this:

<cfset sDate = "07/23/2006-07/20/2006"

<cfset iWeeks = datediff(ww,listLast(sDate),listFirst(sDate))>

iWeeks should give you the difference in weeks..
0

LVL 13

Assisted Solution

usachrisk1983 earned 1600 total points
ID: 17167364
Slight modification to one of your lines:

<cfset iWeeks = datediff(ww,listLast(sDate),listFirst(sDate))>

should be

<cfset iWeeks = datediff(ww,listLast(sDate,'-'),listFirst(sDate,'-'))>

If the data is stored as "07/23/2006-07/20/2006"

This is because both ListFirst and ListLast will be looking for a comma as a delim, and when it doesn't find one, will assume it's just a one item list.
0

LVL 11

Expert Comment

ID: 17168108
yep sir.. agree with you.. i was asleep when I wrote that code..
0

Author Comment

ID: 17189930
I get an error.  It is telling me that ww is undefined.
0

LVL 15

Accepted Solution

tim_cs earned 400 total points
ID: 17190916
Just need to put the ww between quotes

datediff("ww",   etc...
0

LVL 25

Expert Comment

ID: 17225702
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.