Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Get date from day of week

Hi all,

I have dates from 17/12/2015 to 23/12/2015 (in the format DD/MM/YYYY).

Also using the function WeekStart() and WeekEnd(), I can find the start and end of the week for the particular dates.

My requirement is I have a field with the name of the day (Sun,Mon,Tue,.... , Sat).

If for the particular date name of day says Tue, the value should be the date between WeekStart and Weekend which is Tuesday.

Example:

DateWeekStart (Monday)WeekEnd (Sunday)ValueNew_Date
17/12/201514/12/201520/12/2015Tue15/12/2015
18/12/201514/12/201520/12/2015Fri18/12/2015
19/12/201514/12/201520/12/2015Fri18/12/2015
20/12/201514/12/201520/12/2015Wed16/12/2015
21/12/201521/12/201527/12/2015Sat26/12/2015
22/12/201521/12/201527/12/2015Mon21/12/2015
23/12/201521/12/201527/12/2015Fri25/12/2015

Can anyone please help me on this?

Regards,

Anjali Gupta

1 Solution

Accepted Solutions
sunny_talwar

Try this script:

Table:

LOAD Date,

     [WeekStart (Monday)],

     [WeekEnd (Sunday)],

     Value,

     New_Date,

     Date(([WeekStart (Monday)] + Pick(Match(Value, 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'), 0, 1, 2, 3, 4, 5, 6))) as Calculated_New_Date

FROM

[https://community.qlik.com/thread/197804]

(html, codepage is 1252, embedded labels, table is @1);


Capture.PNG

View solution in original post

6 Replies
Anonymous
Not applicable
Author

You want to do it on the base of New_Date Field??

Could you elaborate more?

sunny_talwar

Try this script:

Table:

LOAD Date,

     [WeekStart (Monday)],

     [WeekEnd (Sunday)],

     Value,

     New_Date,

     Date(([WeekStart (Monday)] + Pick(Match(Value, 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'), 0, 1, 2, 3, 4, 5, 6))) as Calculated_New_Date

FROM

[https://community.qlik.com/thread/197804]

(html, codepage is 1252, embedded labels, table is @1);


Capture.PNG

MayilVahanan

Hi

We can achieve this in different ways. Here, 2 methods

MapWeek:

Mapping

LOAD * Inline

[

Value, Num

Mon, 1

Tue, 2

Wed, 3

Thu, 4

Fri, 5

Sat, 6

Sun, 7

];

LOAD *, Date(Date+((Week - WeekValue)*-1)) as FinalDate,

               Date("WeekStart (Monday)" + (WeekValue-1)) as New_Date;

LOAD *, ApplyMap('MapWeek', Text(WeekDay(Date))) as Week, ApplyMap('MapWeek', Value) as WeekValue INLINE [

    Date, WeekStart (Monday), WeekEnd (Sunday), Value

    17/12/2015, 14/12/2015, 20/12/2015, Tue

    18/12/2015, 14/12/2015, 20/12/2015, Fri

    19/12/2015, 14/12/2015, 20/12/2015, Fri

    20/12/2015, 14/12/2015, 20/12/2015, Wed

    21/12/2015, 21/12/2015, 27/12/2015, Sat

    22/12/2015, 21/12/2015, 27/12/2015, Mon

    23/12/2015, 21/12/2015, 27/12/2015, Fri

];

O/P:

Date New_Date FinalDate Week WeekEnd (Sunday) WeekStart (Monday) Value WeekValue
17/12/201515/12/201515/12/2015420/12/201514/12/2015Tue2
18/12/201518/12/201518/12/2015520/12/201514/12/2015Fri5
19/12/201518/12/201518/12/2015620/12/201514/12/2015Fri5
20/12/201516/12/201516/12/2015720/12/201514/12/2015Wed3
21/12/201526/12/201526/12/2015127/12/201521/12/2015Sat6
22/12/201521/12/201521/12/2015227/12/201521/12/2015Mon1
23/12/201525/12/201525/12/2015327/12/201521/12/2015Fri5
Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
Not applicable
Author

Thanks Sunny for the quick response and help.

It worked out perfectly.

Regards,

Anjali Gupta

Not applicable
Author

Thanks for your help also.

sunny_talwar

Awesome, I am glad it helped you