# New to QlikView

Discussion board where members can get started with QlikView.

Highlighted
Contributor III

## How to calculate quarter based on datetime field ?

Hi,

I need to know how quarters in a year will be calculated based on current date time and also based on date field from my database.

If I have a field of type date and need to calculate Quarters (Suppose Q1, Q2, Q3 and Q4), then how to do that thing?

Tags (1)
4 Replies
Honored Contributor II

## Re: How to calculate quarter based on datetime field ?

try tis in ur script Date/calendar table.

'Q' & Ceil(Month([Order Date])/3) As Quarterly,

Employee

## Re: How to calculate quarter based on datetime field ?

=Num(Ceil( Month(MyDate)/ 3 ), 'Q0')

Partner

## Re: How to calculate quarter based on datetime field ?

use some thing like below as Mapping table :

QuartersMap:

rowno() as Month,

'Q' & Ceil (rowno()/3) as Quarter

AUTOGENERATE (12);

Contributor II

## Re: How to calculate quarter based on datetime field ?

HI Try This

QuartersMap:

rowno() as Month,

'Q' & Ceil (rowno()/3) as Quarter

AUTOGENERATE (12);

MasterCalendar:

TempDate AS DATE,

week(TempDate) As Week,

Year(TempDate) As Year,

Month(TempDate) As Month,

Day(TempDate) As Day,

date(monthstart(TempDate), 'MMM-YYYY') as MonthYear,

ApplyMap('QuartersMap', month(TempDate), Null()) as Quarter,

Year(TempDate) & ' ' & ApplyMap('QuartersMap', month(TempDate), Null()) as CalendarYearQuarter,

RIGHT(Year(TempDate) & ' ' & ApplyMap('QuartersMap', month(TempDate), Null()), 2) AS CalendarQuarter,

Week(weekstart(TempDate)) & '-' & WeekYear(TempDate) as WeekYear,

WeekDay(TempDate) as WeekDay

Resident TempCalendar

Order By TempDate ASC;

Drop Table TempCalendar;