Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Can anyone see anything clearl wrong with this script and why it appears to be treating my date as a string?
The code is creating a Weekend date based on a Thursday weekend. The logic is working but when I try to use this in a variable in set analysis it wont recognize it as a date even if I try to format it. But I created the same code converting to a NUM() and it shows the correct number for each date. In my set analysis I am using the max() function to create a variable of the max available week selected then I need to use that in set analysis to compare to the field below but it wont recognize it. No error, it just ignores it. Frustrating but I havent worked with date variables in quite a while.
if(TempDate > weekend(TempDate)-3,
date(floor(weekend(TempDate))+4,'M/D/YYYY'),
date(floor(weekend(TempDate)-3),'M/D/YYYY'))
as THU_WeekEnd,
Hi .I things its looking correct to me
if you convert numbers into date then it will be Previous weekend you want
see the attached file
In my example i have selected 13/03/2013 and previous weekend it showing as 06/03/2013.
Hope this helps
Because you are using the Floor statement this is getting converted to an integer field. If you replace Floor with DayStart and remove the Num function this should return a date in your default date format.
Rather than relying on default formats though you can always force the format with a Date function. Wrap your entire statement in a Date function and it will cause it to display as you want it (remember that dates are only ever numbers - it's only how they display that changes). The code would be:
Date(If(WeekDay(TempDate) = 'Thu', num(floor(TempDate)),
If(WeekDay(TempDate) = 'Fri', num(floor(TempDate))+6,
If(WeekDay(TempDate) = 'Sat', num(floor(TempDate))+5,
If(WeekDay(TempDate) = 'Sun', num(floor(TempDate))+4,
If(WeekDay(TempDate) = 'Mon', num(floor(TempDate))+3,
If(WeekDay(TempDate) = 'Tue', num(floor(TempDate))+2,
If(WeekDay(TempDate) = 'Wed', num(floor(TempDate))+1))))))), 'M/D/YYYY') as Thu_WeekEnd,
You could then use the code I posted above in your variable for getting the max date:
=Date(Max(THU_WeekEnd), 'M/D/YYYY')
This will then give a date in a matching format. Once your date formats match then Set Analysis should start behaving itself.
Steve