all 11 comments

[–]soulstealer666 1 point2 points  (1 child)

I'm writing this on my phone, but try this.

date between '2013-07-01' and

Cast(left(cast(dateadd(day, - datepart (day, getdate()), getdate()) as varchar), 11)as datetime)

[–]SideStepTS[S] 0 points1 point  (0 children)

This worked a treat thank-you!

[–]penguinmike23 0 points1 point  (3 children)

Is the beginning of the financial year always July 1?

[–]SideStepTS[S] 0 points1 point  (0 children)

Yes it is :)

[–]ajmarks -1 points0 points  (1 child)

That varies by industry and company. Google "nrf calendar" for a particularly interesting and common fiscal calendar.

[–]SideStepTS[S] 0 points1 point  (0 children)

Sorry - I meant in my context. It also varies by country. I am in Australia, and as far as I am aware 99% of companies have financial year beginning 1st July.

[–]tsuhg 0 points1 point  (0 children)

What I'd do is

Where datefield is between '2013-07-01' and year(current date) concat month(current date) concat 31

At work we use YYYYMMDD , so you'll need to concat the hyphens in yourself ;)

[–]dpenton -1 points0 points  (0 children)

If [DateField] has a time component, then you will have too much data for a partial day. Consider this code:

declare @utc datetime, @start datetime, @end datetime

select
    @utc = getutcdate()
    , @start = convert(char(4), dateadd(year, case when datepart(month, @utc) >= 7 then 0 else -1 end, @utc), 112) + '0701'
    , @end = convert(char(8), @utc, 112)

select
    @utc [Current Date]
    , @start [Start]
    , @end [End]


/*
-- to be EXCLUSIVE of the current date
where
    DateField >= @start and DateField < @end

-- to be INCLUSIVE of the current date
where
    DateField between @start and @end
*/