Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
sunil-kumar5
Creator II
Creator II

Not getting years and month

Hi Community,

In my scrip I am using below method to create year and month for my table but now sure as why I am getting blank in years and month column while checking in data modeling.

Created_Date,
YEAR(Created_Date) as TYear,
MONTH(Created_Date) as TMonth,

Is there any idea? I did apply the same way before it worked always but not for now.

18 Replies
Kushal_Chawda

That means your dates are not in proper date format

try below. Assuming your date values are in format 'DD-MM-YYYY' you can change the format according to actual format of date value

YEAR(date(date#(Created_Date,'DD-MM-YYYY'))) as TYear,
MONTH(date(date#(Created_Date,'DD-MM-YYYY'))) as TMonth

 

sunil-kumar5
Creator II
Creator II
Author

Hi,

My date format is in DD/MM/YYYY H:MM format. I have tried with chaning the formating but it did'work.

 

Thanks

Taoufiq_Zarra

if not you can always do :

Makedate(left(subfield(Created_Date,'/',3),4),subfield(Created_Date,'/',2),subfield(Created_Date,'/',1)) as Created_Date,
Year(Makedate(left(subfield(Created_Date,'/',3),4),subfield(Created_Date,'/',2),subfield(Created_Date,'/',1))) as TYear,
MONTH(Makedate(left(subfield(Created_Date,'/',3),4),subfield(Created_Date,'/',2),subfield(Created_Date,'/',1))) as TMonth
Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Kushal_Chawda

try below

YEAR(floor(timestamp#(Created_Date,'DD/MM/YYYY hh:mm'))) as TYear,
MONTH(floor(timestamp#(Created_Date,'DD/MM/YYYY hh:mm'))) as TMonth

Kushal_Chawda

or simply change the set variable in main tab as below

SET TimestampFormat='DD/MM/YYYY hh:mm';

then you can use your current logic to get the month and year

sunil-kumar5
Creator II
Creator II
Author

Hi All,

Still same problem, I have applied all the above suggestion. I am sharing the further details below and if anyone can please look into it.

Inbuilt formatinng after loading the data

SET TimeFormat='h:mm:ss';
SET DateFormat='DD/MM/YYYY';
SET TimestampFormat='DD/MM/YYYY hh:mm';

Table first which has the dates:

JOINING_DATE,
YEAR(JOINING_DATE) as JYear,
'Q-'&Ceil(Month(JOINING_DATE)/3) as JQuarter,
MONTH(JOINING_DATE) as JMonth,
'W-'&Week(JOINING_DATE) as JWeek,
WeekDay(JOINING_DATE) as JWeekDay,
Day(JOINING_DATE) as JDay,
CONFIRMATION_DATE,
LEAVING_DATE,
YEAR(LEAVING_DATE) as LYear,
MONTH(LEAVING_DATE) as LMonth,

Now I am placing the data in other table that is TMS:

TMS:
LOAD
COMPANY_CODE,
COMPANY_NAME,
ticket_No,
ticket_subject,
ticket_message,
ticket_CreatedBy,
ticket_CreatedBy_Department,
ticket_assignedto,
ticket_Assignedto_department,
Created_Date, (Here I need to place year and month as stated above)

Please look into this

 

Kushal_Chawda

Can you send a snapshot of CreatedDate values?

Anonymous
Not applicable

Did you check if Created_Date is being loaded as a string? If yes you have to use MakeDate(YYYY [ , MM [ , DD ] ]) function to convert the string into a date?

https://help.qlik.com/en-US/sense/June2020/Subsystems/Hub/Content/Sense_Hub/Scripting/DateAndTimeFun...

sunil-kumar5
Creator II
Creator II
Author

here is an attachment