On 01/09/2016 04:45 AM, Franc Carter wrote:
>
> Hi,
>
> I'm trying to write a short function that returns the last sunday of
> the week of a given date, code below
>
> def getSunday(day):
>
> day = day.cast("date")
>
> sun = next_day(day, "Sunday")
>
>
My Python is not particularly good, so I'm afraid I don't understand what
that mean
cheers
On 9 January 2016 at 14:45, Franc Carter wrote:
>
> Hi,
>
> I'm trying to write a short function that returns the last sunday of the
> week of a given date, code below
>
> def
Got it, I needed to use the when/otherwise construct - code below
def getSunday(day):
day = day.cast("date")
sun = next_day(day, "Sunday")
n = datediff(sun,day)
x = when(n==7,day).otherwise(sun)
return x
On 10 January 2016 at 08:41, Franc Carter
Hi,
I'm trying to write a short function that returns the last sunday of the
week of a given date, code below
def getSunday(day):
day = day.cast("date")
sun = next_day(day, "Sunday")
n = datediff(sun,day)
if (n == 7):
return day
else:
return sun
this